#!/usr/local/bin/perl # # Author: Mitch Richling # IP: Copyright 1994 by Mitch Richling. All rights reserved. # Key word: lorenz strange attractor povray Euler # Notes: This is a very simple program to generate a curve based # on Lorenz's attractor. It uses Euler's method to solve the # equations. The "curve" consists of a series of spheres # placed at each point found on the curve. The spheres # are connected with cylinders. Note that this program # is simple enough to be coded with Povray itself. This # Perl version is much shorter than the C version. $maxBalls = 10000; $tDelta = 0.01; $x = 0.1; $y = 0.0; $z = 0.0; $a = 10.0; $b = 28.0; $c = 8.0 / 3.0; printf(STDERR "Computation starting...\n"); printf("sphere {<%f,%f,%f>, %f texture { crvTex } }\n", $x, $y, $z, 0.2); for($numBalls=0;$numBalls<$maxBalls;$numBalls++) { $xNew = $x + $a*($y-$x)*$tDelta; $yNew = $y + ($x*($b-$z)-$y)*$tDelta; $zNew = $z + ($x*$y-$c*$z)*$tDelta; if(($numBalls % int($maxBalls/20)) == 0) { printf(STDERR "Step: %6d tDelta: %15.3f x: %15.2f y: %15.2f z: %15.2f\n", $numBalls, $tDelta, $x, $y, $z); } printf("sphere {<%f,%f,%f>, %f texture { crvTex } }\n", $xNew, $yNew, $zNew, 0.1); printf("cylinder {<%f,%f,%f>, <%f,%f,%f>, %f texture { crvTex } }\n", $x, $y, $z, $xNew, $yNew, $zNew, 0.2); $x=$xNew; $y=$yNew; $z=$zNew; }