// -*- Coding:us-ascii-unix; fill-column:132 -*- 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// @file      lorenz1.inc
// @author    Mitch Richling <http://www.mitchr.me/>
// @Copyright Copyright 1994,1997,2014 by Mitch Richling.  All rights reserved.
// @Revision  $Revision: 1.1 $ 
// @SCMdate   $Date: 2014/10/10 19:36:53 $
// @brief     Generate a PovRay include file for the lorenz strange attractor. @EOL
// @Keywords  lorenz strange attractor
// @Std       Povray_3.5
//
// 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.
// Alternate implimentations: lorenz1.pl, lorenz1.c           

//----------------------------------------------------------------------------------------------------------------------------------

#declare tDelta = 0.01;
#declare xCur = 0.1;
#declare yCur = 0.0;
#declare zCur = 0;
#declare a = 10;
#declare b = 28;
#declare c = 8.0 / 3.0;

#declare numBalls=1;
#while (numBalls < 10000)
    #declare xNew = xCur + a*(yCur-xCur)*tDelta;
    #declare yNew = yCur + (xCur*(b-zCur)-yCur)*tDelta;
    #declare zNew = zCur + (xCur*yCur-c*zCur)*tDelta;

    sphere {<xNew,yNew,zNew>, 0.2 texture { crvTex } }
    cylinder {<xCur,yCur,zCur>, <xNew,yNew,zNew>, 0.2 texture { crvTex } }
    
    #declare xCur=xNew;
    #declare yCur=yNew;
    #declare zCur=zNew;

    #declare numBalls=numBalls+1;
#end