$cosa = cos($rad); $sina = sin($rad); $x = $this->x * $cosa - $this->y * $sina; $y = $this->x * $sina + $this->y * $cosa; return new Point3D($x, $y, $this->z); } public function project($width, $height, $fov, $viewerDistance) { $factor = (double) $fov / ($viewerDistance + $this->z); $x = $this->x * $factor + $width / 2; $y = -$this->y * $factor + $height / 2; return new Point3D($x, $y, $this->z); } } $img_width = CLI\Misc::cols(); $img_height = CLI\Misc::rows(); $width = 0.8; $height = 0.8; $depth = 0.8; $hWidth = $width / 2; $hHeight = $height / 2; $hDepth = $depth / 2; /* Define the 8 vertices of the cube. */ $vertices = array(new Point3D(-$hWidth, $hHeight, -$hDepth), new Point3D($hWidth, $hHeight, -$hDepth), new Point3D($hWidth, -$hHeight, -$hDepth), new Point3D(-$hWidth, -$hHeight, -$hDepth), new Point3D(-$hWidth, $hHeight, $hDepth), new Point3D($hWidth, $hHeight, $hDepth), new Point3D($hWidth, -$hHeight, $hDepth), new Point3D(-$hWidth, -$hHeight, $hDepth)); /* Define the vertices that compose each of the 6 faces. These numbers are indices to the vertex list defined above. */ $faces = array(array(0, 1, 2, 3), array(1, 5, 6, 2), array(5, 4, 7, 6), array(4, 0, 3, 7), array(0, 4, 5, 1), array(3, 2, 6, 7)); /* Assign random values for the angles that describe the cube orientation. */ $nnn = 0; while (true) { CLI\Erase::screen();
<?php require '__autoload.php'; $func = function ($i, $gap) { $j = $i / 10; $size = CLI\Misc::cols() - $gap; return round(sin($j) * $size / 2 + $size / 2); }; $cofunc = function ($i, $gap) { $j = $i / 10; $size = CLI\Misc::rows() - $gap; return round(cos($j) * $size / 2 + $size / 2); }; for ($i = 0; $i <= 100; $i++) { CLI\Erase::screen(); // $a = $func( $i, 2 ); // $b = $func( $i, 4 ); // $c = $func( $i, 8 ); // $d = $func( $i, 16 ); // // CLI\Graphics::box($a, 1, $a + 3, 3); // CLI\Graphics::box($b, 3, $b + 7, 7); // CLI\Graphics::box($c, 7, $c + 15, 15); // CLI\Graphics::box($d, 15, $d + 31, 31); for ($j = 0; $j <= 15; $j += 3) { $k = ($j + 1) * 2; $d = $func($i, $k); $e = $cofunc($i, $k); CLI\Graphics::box($d, $e, $d + $k, $e + $k); } usleep(100000);