cvs: pear /Image_3D/Image/3D Renderer.php /Image_3D/Image/3D/Driver ASCII.php /Image_3D/Image/3D/Renderer Isometric.php Perspectively.php
/Image_3D/docs/examples ascii.php
| From: | Kore Nordmann | Date: | Sat, 20 Aug 2005 11:32:23 +0000 |
| Subject: | cvs: pear /Image_3D/Image/3D Renderer.php /Image_3D/Image/3D/Driver ASCII.php /Image_3D/Image/3D/Renderer Isometric.php Perspectively.php /Image_3D/docs/examples ascii.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-34180@lists.php.net to get a copy of this message | ||
kore Sat Aug 20 07:32:23 2005 EDT
Modified files:
/pear/Image_3D/Image/3D Renderer.php
/pear/Image_3D/Image/3D/Driver ASCII.php
/pear/Image_3D/Image/3D/Renderer Isometric.php Perspectively.php
/pear/Image_3D/docs/examples ascii.php
Log:
- Several optimizations to speed up the ascii demo
http://cvs.php.net/diff.php/pear/Image_3D/Image/3D/Renderer.php?r1=1.3&r2=1.4&ty=u Index: pear/Image_3D/Image/3D/Renderer.php diff -u pear/Image_3D/Image/3D/Renderer.php:1.3 pear/Image_3D/Image/3D/Renderer.php:1.4 --- pear/Image_3D/Image/3D/Renderer.php:1.3 Sat Aug 13 03:59:26 2005 +++ pear/Image_3D/Image/3D/Renderer.php Sat Aug 20 07:32:20 2005 @@ -27,7 +27,7 @@ * @author Kore Nordmann <3d@kore-nordmann.de> * @copyright 1997-2005 Kore Nordmann * @license http://www.gnu.org/licenses/lgpl.txt lgpl 2.1 - * @version CVS: $Id: Renderer.php,v 1.3 2005/08/13 07:59:26 kore Exp $ + * @version CVS: $Id: Renderer.php,v 1.4 2005/08/20 11:32:20 kore Exp $ * @link http://pear.php.net/package/PackageName * @since File available since Release 0.1.0 */ @@ -120,7 +120,7 @@ } public function setSize($x, $y) { - $this->_size = array($x, $y); + $this->_size = array($x / 2, $y / 2); } public function setBackgroundColor(Image_3D_Color $color) { @@ -200,13 +200,13 @@ $this->_sortPolygones(); // Draw background - $this->_driver->createImage($this->_size[0], $this->_size[1]); + $this->_driver->createImage($this->_size[0] * 2, $this->_size[1] * 2); $this->_driver->setBackground($this->_background); - // Calculate Colors + // Create polygones in driver $this->_shade(); - // Save + // Save image $this->_driver->save($file); } } http://cvs.php.net/diff.php/pear/Image_3D/Image/3D/Driver/ASCII.php?r1=1.1&r2=1.2&ty=u Index: pear/Image_3D/Image/3D/Driver/ASCII.php diff -u pear/Image_3D/Image/3D/Driver/ASCII.php:1.1 pear/Image_3D/Image/3D/Driver/ASCII.php:1.2 --- pear/Image_3D/Image/3D/Driver/ASCII.php:1.1 Thu Aug 11 14:11:28 2005 +++ pear/Image_3D/Image/3D/Driver/ASCII.php Sat Aug 20 07:32:23 2005 @@ -101,10 +101,11 @@ } protected function _mixColor($old, $new) { + $faktor = (1 - $new[3]) * $old[3]; // slight speed improvement return array( - $old[0] * (1 - $new[3]) * $old[3] + $new[0] * $new[3], - $old[1] * (1 - $new[3]) * $old[3] + $new[1] * $new[3], - $old[2] * (1 - $new[3]) * $old[3] + $new[2] * $new[3], + $old[0] * $faktor + $new[0] * $new[3], + $old[1] * $faktor + $new[1] * $new[3], + $old[2] * $faktor + $new[2] * $new[3], $old[3] * $old[3] + $new[3] ); @@ -113,8 +114,8 @@ public function setBackground(Image_3D_Color $color) { $bg = $this->_getColor($color); - for ($x = 0; $x < $this->_size[0]; $x++) { - for ($y = 0; $y < $this->_size[1]; $y++) { + for ($x = 0; $x < $this->_size[0]; ++$x) { + for ($y = 0; $y < $this->_size[1]; ++$y) { $this->_image[$x][$y] = $bg; } } @@ -132,7 +133,7 @@ $zdiff = ($z2 - $z1) / $steps; $points = array('height' => array(), 'coverage' => array()); - for ($i = 0; $i < $steps; $i++) { + for ($i = 0; $i < $steps; ++$i) { $x = $x1 + $i * $xdiff; $xFloor = floor($x); $xCeil = ceil($x); @@ -210,7 +211,7 @@ $this->_heigth[$x][$start][(int) ($zStart * 100)] = $this->_getColor($polygon->getColor(), $points['coverage'][$x][$start]); // the way between - for ($y = $start + 1; $y < $end; $y++) { + for ($y = $start + 1; $y < $end; ++$y) { $this->_heigth[$x][$y][(int) (($zStart + $zStep * ($y - $start)) * 100)] = $this->_getColor($polygon->getColor()); } @@ -247,13 +248,13 @@ $output = "\033[2J"; $lastColor = ''; - for ($y = 0; $y < $asciiHeight; $y++) { - for ($x = 0; $x < $asciiWidth; $x++) { + for ($y = 0; $y < $asciiHeight; ++$y) { + for ($x = 0; $x < $asciiWidth; ++$x) { // Get pixelarray $char = 0; $charColor = array(0, 0, 0); - for ($xi = 0; $xi < 2; $xi++) { - for ($yi = 0; $yi < 3; $yi++) { + for ($xi = 0; $xi < 2; ++$xi) { + for ($yi = 0; $yi < 3; ++$yi) { $xPos = $x * 2 + $xi; $yPos = $y * 6 + $yi; $color = $this->_image[$xPos][$yPos]; @@ -263,7 +264,7 @@ krsort($points); foreach ($points as $newColor) $color = $this->_mixColor($color, $newColor); } - if ((($color[0] + $color[1] + $color[2]) / 3) < IMAGE_3D_DRIVER_ASCII_GRAY) $char |= pow(2, $yi + ($xi * 3)); + if ((($color[0] + $color[1] + $color[2]) / 3) > IMAGE_3D_DRIVER_ASCII_GRAY) $char |= pow(2, $yi + ($xi * 3)); $charColor[0] += $color[0]; $charColor[1] += $color[1]; $charColor[2] += $color[2]; http://cvs.php.net/diff.php/pear/Image_3D/Image/3D/Renderer/Isometric.php?r1=1.2&r2=1.3&ty=u Index: pear/Image_3D/Image/3D/Renderer/Isometric.php diff -u pear/Image_3D/Image/3D/Renderer/Isometric.php:1.2 pear/Image_3D/Image/3D/Renderer/Isometric.php:1.3 --- pear/Image_3D/Image/3D/Renderer/Isometric.php:1.2 Sun Jul 24 07:41:10 2005 +++ pear/Image_3D/Image/3D/Renderer/Isometric.php Sat Aug 20 07:32:23 2005 @@ -27,7 +27,7 @@ * @author Kore Nordmann <3d@kore-nordmann.de> * @copyright 1997-2005 Kore Nordmann * @license http://www.gnu.org/licenses/lgpl.txt lgpl 2.1 - * @version CVS: $Id: Isometric.php,v 1.2 2005/07/24 11:41:10 kore Exp $ + * @version CVS: $Id: Isometric.php,v 1.3 2005/08/20 11:32:23 kore Exp $ * @link http://pear.php.net/package/PackageName * @since File available since Release 0.1.0 */ @@ -50,8 +50,8 @@ protected function _calculateScreenCoordiantes(Image_3D_Point $point) { $point->setScreenCoordinates( - $point->getX() - ($point->getZ() * .35) + $this->_size[0] / 2, - $point->getY() + ($point->getZ() * .35) + $this->_size[1] / 2 + $point->getX() - ($point->getZ() * .35) + $this->_size[0], + $point->getY() + ($point->getZ() * .35) + $this->_size[1] ); } http://cvs.php.net/diff.php/pear/Image_3D/Image/3D/Renderer/Perspectively.php?r1=1.3&r2=1.4&ty=u Index: pear/Image_3D/Image/3D/Renderer/Perspectively.php diff -u pear/Image_3D/Image/3D/Renderer/Perspectively.php:1.3 pear/Image_3D/Image/3D/Renderer/Perspectively.php:1.4 --- pear/Image_3D/Image/3D/Renderer/Perspectively.php:1.3 Thu Aug 11 14:11:28 2005 +++ pear/Image_3D/Image/3D/Renderer/Perspectively.php Sat Aug 20 07:32:23 2005 @@ -27,7 +27,7 @@ * @author Kore Nordmann <3d@kore-nordmann.de> * @copyright 1997-2005 Kore Nordmann * @license http://www.gnu.org/licenses/lgpl.txt lgpl 2.1 - * @version CVS: $Id: Perspectively.php,v 1.3 2005/08/11 18:11:28 kore Exp $ + * @version CVS: $Id: Perspectively.php,v 1.4 2005/08/20 11:32:23 kore Exp $ * @link http://pear.php.net/package/PackageName * @since File available since Release 0.1.0 */ @@ -49,12 +49,12 @@ class Image_3D_Renderer_Perspectively extends Image_3D_Renderer { protected function _calculateScreenCoordiantes(Image_3D_Point $point) { - $viewpoint = (float) max($this->_size); - $distance = (float) max($this->_size); + $viewpoint = 500.; + $distance = 500.; $point->setScreenCoordinates( - $viewpoint * $point->getX() / ($point->getZ() + $distance) + $this->_size[0] / 2, - $viewpoint * $point->getY() / ($point->getZ() + $distance) + $this->_size[1] / 2 + $viewpoint * $point->getX() / ($point->getZ() + $distance) + $this->_size[0], + $viewpoint * $point->getY() / ($point->getZ() + $distance) + $this->_size[1] ); } http://cvs.php.net/diff.php/pear/Image_3D/docs/examples/ascii.php?r1=1.2&r2=1.3&ty=u Index: pear/Image_3D/docs/examples/ascii.php diff -u pear/Image_3D/docs/examples/ascii.php:1.2 pear/Image_3D/docs/examples/ascii.php:1.3 --- pear/Image_3D/docs/examples/ascii.php:1.2 Sat Aug 13 03:59:26 2005 +++ pear/Image_3D/docs/examples/ascii.php Sat Aug 20 07:32:23 2005 @@ -1,36 +1,81 @@ <?php +$images = 'php://output'; +$times_file = 'times.txt'; +$iterations = 50; + +$GLOBALS['times'] = array(); +$GLOBALS['times_fp'] = fopen($times_file, 'a'); + +function getTime($string = null) { + if (is_string($string)) { + $GLOBALS['times'][$string] = microtime(true); + fwrite($GLOBALS['times_fp'], sprintf("%sStart '%s'\n", str_repeat("\t", count($GLOBALS['times']) - 1), $string)); + } else { + $keys = array_keys($GLOBALS['times']); + $last = end($keys); + fwrite($GLOBALS['times_fp'], sprintf("%s-> %2.4fs\n", str_repeat("\t", count($GLOBALS['times']) - 1), microtime(true) - $GLOBALS['times'][$last])); + unset($GLOBALS['times'][$last]); + } +} + +getTime('Start'); + +getTime('Initialize classes'); set_time_limit(0); ini_set('memory_limit', '24M'); set_include_path(realpath(dirname(__FILE__) . '/../..')); require_once('Image/3D.php'); +getTime(); +getTime('Create world'); $world = new Image_3D(); -$world->setColor(new Image_3D_Color(255, 255, 255)); +$world->setColor(new Image_3D_Color(0, 0, 0)); +getTime(); -$light1 = $world->createLight(-100, -100, -100); -$light1->setColor(new Image_3D_Color(255, 0, 0)); - -//$light2 = $world->createLight(100, -200, 0); -//$light2->setColor(new Image_3D_Color(0, 255, 0)); +getTime('Create lights'); +$light1 = $world->createLight(-500, -500, -500); +$light1->setColor(new Image_3D_Color(255, 255, 255)); + +$light2 = $world->createLight(0, 500, -550); +$light2->setColor(new Image_3D_Color(0, 255, 0)); +getTime(); +getTime('Create objects'); $p1 = $world->createObject('cube', array(80, 80, 80)); $p1->setColor(new Image_3D_Color(200, 200, 200)); $p1->transform($world->createMatrix('Rotation', array(45, 45, 0))); +getTime(); +getTime('Set options'); $world->setOption(Image_3D::IMAGE_3D_OPTION_BF_CULLING, false); $world->setOption(Image_3D::IMAGE_3D_OPTION_FILLED, true); +getTime(); +getTime('Create renderer and driver'); $rotation = $world->createMatrix('Rotation', array(2, 5, 0)); $renderer = $world->createRenderer('perspectively'); $driver = $world->createDriver('ASCII'); +getTime(); -$world->render(2 * 80, 6 * 30, 'php://output'); - -while (1) { +getTime('Create initial picture'); +$world->render(2 * 80, 6 * 30, $images); +getTime(); + +getTime('Start animation'); +$start = microtime(true); +$i = 0; +while ($i++ < $iterations) { + getTime('Render image ' . $i); $p1->transform($rotation); $driver->reset(); - $renderer->render('php://output'); + $renderer->render($images); + getTime(); } +getTime(); + +$time = microtime(true) - $start; +printf("%2.2f fps\n", $iterations / $time); +getTime(); ?>
http://cvs.php.net/diff.php/pear/Image_3D/Image/3D/Renderer.php?r1=1.3&r2=1.4&ty=u Index: pear/Image_3D/Image/3D/Renderer.php diff -u pear/Image_3D/Image/3D/Renderer.php:1.3 pear/Image_3D/Image/3D/Renderer.php:1.4 --- pear/Image_3D/Image/3D/Renderer.php:1.3 Sat Aug 13 03:59:26 2005 +++ pear/Image_3D/Image/3D/Renderer.php Sat Aug 20 07:32:20 2005 @@ -27,7 +27,7 @@ * @author Kore Nordmann <3d@kore-nordmann.de> * @copyright 1997-2005 Kore Nordmann * @license http://www.gnu.org/licenses/lgpl.txt lgpl 2.1 - * @version CVS: $Id: Renderer.php,v 1.3 2005/08/13 07:59:26 kore Exp $ + * @version CVS: $Id: Renderer.php,v 1.4 2005/08/20 11:32:20 kore Exp $ * @link http://pear.php.net/package/PackageName * @since File available since Release 0.1.0 */ @@ -120,7 +120,7 @@ } public function setSize($x, $y) { - $this->_size = array($x, $y); + $this->_size = array($x / 2, $y / 2); } public function setBackgroundColor(Image_3D_Color $color) { @@ -200,13 +200,13 @@ $this->_sortPolygones(); // Draw background - $this->_driver->createImage($this->_size[0], $this->_size[1]); + $this->_driver->createImage($this->_size[0] * 2, $this->_size[1] * 2); $this->_driver->setBackground($this->_background); - // Calculate Colors + // Create polygones in driver $this->_shade(); - // Save + // Save image $this->_driver->save($file); } } http://cvs.php.net/diff.php/pear/Image_3D/Image/3D/Driver/ASCII.php?r1=1.1&r2=1.2&ty=u Index: pear/Image_3D/Image/3D/Driver/ASCII.php diff -u pear/Image_3D/Image/3D/Driver/ASCII.php:1.1 pear/Image_3D/Image/3D/Driver/ASCII.php:1.2 --- pear/Image_3D/Image/3D/Driver/ASCII.php:1.1 Thu Aug 11 14:11:28 2005 +++ pear/Image_3D/Image/3D/Driver/ASCII.php Sat Aug 20 07:32:23 2005 @@ -101,10 +101,11 @@ } protected function _mixColor($old, $new) { + $faktor = (1 - $new[3]) * $old[3]; // slight speed improvement return array( - $old[0] * (1 - $new[3]) * $old[3] + $new[0] * $new[3], - $old[1] * (1 - $new[3]) * $old[3] + $new[1] * $new[3], - $old[2] * (1 - $new[3]) * $old[3] + $new[2] * $new[3], + $old[0] * $faktor + $new[0] * $new[3], + $old[1] * $faktor + $new[1] * $new[3], + $old[2] * $faktor + $new[2] * $new[3], $old[3] * $old[3] + $new[3] ); @@ -113,8 +114,8 @@ public function setBackground(Image_3D_Color $color) { $bg = $this->_getColor($color); - for ($x = 0; $x < $this->_size[0]; $x++) { - for ($y = 0; $y < $this->_size[1]; $y++) { + for ($x = 0; $x < $this->_size[0]; ++$x) { + for ($y = 0; $y < $this->_size[1]; ++$y) { $this->_image[$x][$y] = $bg; } } @@ -132,7 +133,7 @@ $zdiff = ($z2 - $z1) / $steps; $points = array('height' => array(), 'coverage' => array()); - for ($i = 0; $i < $steps; $i++) { + for ($i = 0; $i < $steps; ++$i) { $x = $x1 + $i * $xdiff; $xFloor = floor($x); $xCeil = ceil($x); @@ -210,7 +211,7 @@ $this->_heigth[$x][$start][(int) ($zStart * 100)] = $this->_getColor($polygon->getColor(), $points['coverage'][$x][$start]); // the way between - for ($y = $start + 1; $y < $end; $y++) { + for ($y = $start + 1; $y < $end; ++$y) { $this->_heigth[$x][$y][(int) (($zStart + $zStep * ($y - $start)) * 100)] = $this->_getColor($polygon->getColor()); } @@ -247,13 +248,13 @@ $output = "\033[2J"; $lastColor = ''; - for ($y = 0; $y < $asciiHeight; $y++) { - for ($x = 0; $x < $asciiWidth; $x++) { + for ($y = 0; $y < $asciiHeight; ++$y) { + for ($x = 0; $x < $asciiWidth; ++$x) { // Get pixelarray $char = 0; $charColor = array(0, 0, 0); - for ($xi = 0; $xi < 2; $xi++) { - for ($yi = 0; $yi < 3; $yi++) { + for ($xi = 0; $xi < 2; ++$xi) { + for ($yi = 0; $yi < 3; ++$yi) { $xPos = $x * 2 + $xi; $yPos = $y * 6 + $yi; $color = $this->_image[$xPos][$yPos]; @@ -263,7 +264,7 @@ krsort($points); foreach ($points as $newColor) $color = $this->_mixColor($color, $newColor); } - if ((($color[0] + $color[1] + $color[2]) / 3) < IMAGE_3D_DRIVER_ASCII_GRAY) $char |= pow(2, $yi + ($xi * 3)); + if ((($color[0] + $color[1] + $color[2]) / 3) > IMAGE_3D_DRIVER_ASCII_GRAY) $char |= pow(2, $yi + ($xi * 3)); $charColor[0] += $color[0]; $charColor[1] += $color[1]; $charColor[2] += $color[2]; http://cvs.php.net/diff.php/pear/Image_3D/Image/3D/Renderer/Isometric.php?r1=1.2&r2=1.3&ty=u Index: pear/Image_3D/Image/3D/Renderer/Isometric.php diff -u pear/Image_3D/Image/3D/Renderer/Isometric.php:1.2 pear/Image_3D/Image/3D/Renderer/Isometric.php:1.3 --- pear/Image_3D/Image/3D/Renderer/Isometric.php:1.2 Sun Jul 24 07:41:10 2005 +++ pear/Image_3D/Image/3D/Renderer/Isometric.php Sat Aug 20 07:32:23 2005 @@ -27,7 +27,7 @@ * @author Kore Nordmann <3d@kore-nordmann.de> * @copyright 1997-2005 Kore Nordmann * @license http://www.gnu.org/licenses/lgpl.txt lgpl 2.1 - * @version CVS: $Id: Isometric.php,v 1.2 2005/07/24 11:41:10 kore Exp $ + * @version CVS: $Id: Isometric.php,v 1.3 2005/08/20 11:32:23 kore Exp $ * @link http://pear.php.net/package/PackageName * @since File available since Release 0.1.0 */ @@ -50,8 +50,8 @@ protected function _calculateScreenCoordiantes(Image_3D_Point $point) { $point->setScreenCoordinates( - $point->getX() - ($point->getZ() * .35) + $this->_size[0] / 2, - $point->getY() + ($point->getZ() * .35) + $this->_size[1] / 2 + $point->getX() - ($point->getZ() * .35) + $this->_size[0], + $point->getY() + ($point->getZ() * .35) + $this->_size[1] ); } http://cvs.php.net/diff.php/pear/Image_3D/Image/3D/Renderer/Perspectively.php?r1=1.3&r2=1.4&ty=u Index: pear/Image_3D/Image/3D/Renderer/Perspectively.php diff -u pear/Image_3D/Image/3D/Renderer/Perspectively.php:1.3 pear/Image_3D/Image/3D/Renderer/Perspectively.php:1.4 --- pear/Image_3D/Image/3D/Renderer/Perspectively.php:1.3 Thu Aug 11 14:11:28 2005 +++ pear/Image_3D/Image/3D/Renderer/Perspectively.php Sat Aug 20 07:32:23 2005 @@ -27,7 +27,7 @@ * @author Kore Nordmann <3d@kore-nordmann.de> * @copyright 1997-2005 Kore Nordmann * @license http://www.gnu.org/licenses/lgpl.txt lgpl 2.1 - * @version CVS: $Id: Perspectively.php,v 1.3 2005/08/11 18:11:28 kore Exp $ + * @version CVS: $Id: Perspectively.php,v 1.4 2005/08/20 11:32:23 kore Exp $ * @link http://pear.php.net/package/PackageName * @since File available since Release 0.1.0 */ @@ -49,12 +49,12 @@ class Image_3D_Renderer_Perspectively extends Image_3D_Renderer { protected function _calculateScreenCoordiantes(Image_3D_Point $point) { - $viewpoint = (float) max($this->_size); - $distance = (float) max($this->_size); + $viewpoint = 500.; + $distance = 500.; $point->setScreenCoordinates( - $viewpoint * $point->getX() / ($point->getZ() + $distance) + $this->_size[0] / 2, - $viewpoint * $point->getY() / ($point->getZ() + $distance) + $this->_size[1] / 2 + $viewpoint * $point->getX() / ($point->getZ() + $distance) + $this->_size[0], + $viewpoint * $point->getY() / ($point->getZ() + $distance) + $this->_size[1] ); } http://cvs.php.net/diff.php/pear/Image_3D/docs/examples/ascii.php?r1=1.2&r2=1.3&ty=u Index: pear/Image_3D/docs/examples/ascii.php diff -u pear/Image_3D/docs/examples/ascii.php:1.2 pear/Image_3D/docs/examples/ascii.php:1.3 --- pear/Image_3D/docs/examples/ascii.php:1.2 Sat Aug 13 03:59:26 2005 +++ pear/Image_3D/docs/examples/ascii.php Sat Aug 20 07:32:23 2005 @@ -1,36 +1,81 @@ <?php +$images = 'php://output'; +$times_file = 'times.txt'; +$iterations = 50; + +$GLOBALS['times'] = array(); +$GLOBALS['times_fp'] = fopen($times_file, 'a'); + +function getTime($string = null) { + if (is_string($string)) { + $GLOBALS['times'][$string] = microtime(true); + fwrite($GLOBALS['times_fp'], sprintf("%sStart '%s'\n", str_repeat("\t", count($GLOBALS['times']) - 1), $string)); + } else { + $keys = array_keys($GLOBALS['times']); + $last = end($keys); + fwrite($GLOBALS['times_fp'], sprintf("%s-> %2.4fs\n", str_repeat("\t", count($GLOBALS['times']) - 1), microtime(true) - $GLOBALS['times'][$last])); + unset($GLOBALS['times'][$last]); + } +} + +getTime('Start'); + +getTime('Initialize classes'); set_time_limit(0); ini_set('memory_limit', '24M'); set_include_path(realpath(dirname(__FILE__) . '/../..')); require_once('Image/3D.php'); +getTime(); +getTime('Create world'); $world = new Image_3D(); -$world->setColor(new Image_3D_Color(255, 255, 255)); +$world->setColor(new Image_3D_Color(0, 0, 0)); +getTime(); -$light1 = $world->createLight(-100, -100, -100); -$light1->setColor(new Image_3D_Color(255, 0, 0)); - -//$light2 = $world->createLight(100, -200, 0); -//$light2->setColor(new Image_3D_Color(0, 255, 0)); +getTime('Create lights'); +$light1 = $world->createLight(-500, -500, -500); +$light1->setColor(new Image_3D_Color(255, 255, 255)); + +$light2 = $world->createLight(0, 500, -550); +$light2->setColor(new Image_3D_Color(0, 255, 0)); +getTime(); +getTime('Create objects'); $p1 = $world->createObject('cube', array(80, 80, 80)); $p1->setColor(new Image_3D_Color(200, 200, 200)); $p1->transform($world->createMatrix('Rotation', array(45, 45, 0))); +getTime(); +getTime('Set options'); $world->setOption(Image_3D::IMAGE_3D_OPTION_BF_CULLING, false); $world->setOption(Image_3D::IMAGE_3D_OPTION_FILLED, true); +getTime(); +getTime('Create renderer and driver'); $rotation = $world->createMatrix('Rotation', array(2, 5, 0)); $renderer = $world->createRenderer('perspectively'); $driver = $world->createDriver('ASCII'); +getTime(); -$world->render(2 * 80, 6 * 30, 'php://output'); - -while (1) { +getTime('Create initial picture'); +$world->render(2 * 80, 6 * 30, $images); +getTime(); + +getTime('Start animation'); +$start = microtime(true); +$i = 0; +while ($i++ < $iterations) { + getTime('Render image ' . $i); $p1->transform($rotation); $driver->reset(); - $renderer->render('php://output'); + $renderer->render($images); + getTime(); } +getTime(); + +$time = microtime(true) - $start; +printf("%2.2f fps\n", $iterations / $time); +getTime(); ?>