コード例 #1
0
ファイル: Render.class.php プロジェクト: arioch31/anarstock
 public function renderSegment(Vertex $origin, Vertex $end)
 {
     $ox = round($origin->get_x());
     $oy = round($origin->get_y());
     $ex = round($end->get_x());
     $ey = round($end->get_y());
     $size = sqrt(pow($ex - $ox, 2) + pow($ey - $oy, 2));
     $dx = round($ox - $ex >= 0 ? $ox - $ex : $ex - $ox);
     $dy = round($oy - $ey >= 0 ? $oy - $ey : $ey - $oy);
     $sx = round($ox < $ex ? 1 : -1);
     $sy = round($oy < $ey ? 1 : -1);
     $errx = round($dx > $dy ? $dx : -$dy) / 2;
     while ($ox != $ex || $oy != $ey) {
         $current_size = sqrt(pow($ex - $ox, 2) + pow($ey - $oy, 2));
         $this->renderVertex(new Vertex(['x' => $ox, 'y' => $oy, 'z' => 1, 'color' => $origin->get_color()->sub($end->get_color())->mult(1 - $current_size / $size)]));
         $erry = $errx;
         if ($erry > -$dx) {
             $errx -= $dy;
             $ox += $sx;
         }
         if ($erry < $dy) {
             $errx += $dx;
             $oy += $sy;
         }
     }
     $this->renderVertex(new Vertex(['x' => $ox, 'y' => $oy, 'z' => 1, 'color' => $end->get_color()]));
     return;
 }