$angleZ = 15 + $nnn++ / 2; $angleY = -30 + +($nnn++ / 3); /* It will store transformed vertices. */ $t = array(); $l = array(); /* Transform all the vertices. */ foreach ($vertices as $v) { $rotated = $v->rotateX($angleX)->rotateY($angleY)->rotateZ($angleZ); $t[] = $rotated->project($img_width, $img_height, 256, 6); $l[] = $rotated->project($img_width, $img_height, 256, 9); } $avgZ = array(); foreach ($faces as $index => $f) { $avgZ["{$index}"] = ($t[$f[0]]->z + $t[$f[1]]->z + $t[$f[2]]->z + $t[$f[3]]->z) / 4.0; } arsort($avgZ); foreach ($avgZ as $index => $z) { $f = $faces[$index]; $points = array($l[$f[0]]->x, $l[$f[0]]->y, $l[$f[1]]->x, $l[$f[1]]->y, $l[$f[2]]->x, $l[$f[2]]->y, $l[$f[3]]->x, $l[$f[3]]->y); CLI\Graphics::line($l[$f[0]]->x, $l[$f[0]]->y, $l[$f[1]]->x, $l[$f[1]]->y, '.'); CLI\Graphics::line($l[$f[1]]->x, $l[$f[1]]->y, $l[$f[2]]->x, $l[$f[2]]->y, '.'); CLI\Graphics::line($l[$f[2]]->x, $l[$f[2]]->y, $l[$f[3]]->x, $l[$f[3]]->y, '.'); CLI\Graphics::line($l[$f[3]]->x, $l[$f[3]]->y, $l[$f[0]]->x, $l[$f[0]]->y, '.'); $points = array($t[$f[0]]->x, $t[$f[0]]->y, $t[$f[1]]->x, $t[$f[1]]->y, $t[$f[2]]->x, $t[$f[2]]->y, $t[$f[3]]->x, $t[$f[3]]->y); CLI\Graphics::line($t[$f[0]]->x, $t[$f[0]]->y, $t[$f[1]]->x, $t[$f[1]]->y); CLI\Graphics::line($t[$f[1]]->x, $t[$f[1]]->y, $t[$f[2]]->x, $t[$f[2]]->y); CLI\Graphics::line($t[$f[2]]->x, $t[$f[2]]->y, $t[$f[3]]->x, $t[$f[3]]->y); CLI\Graphics::line($t[$f[3]]->x, $t[$f[3]]->y, $t[$f[0]]->x, $t[$f[0]]->y); } usleep(50000); }
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); }