[sdiy] Digital simulation of the Lorenz attractor

Jaroslaw Ziembicki aon.912230836 at aon.at
Fri Jul 4 20:07:48 CEST 2003


Hi,
I wrote a C program that simulates the Lorenz attractor
and plots the results. The graphic mode should be set.
Here is the basic subroutine. Maybe somebody will find
it useful.
Regards
Jarek


void Lorenz(void)
{
/* simulation variables/parameters: */
  float x = 0.1;
  float y = 0.0;
  float z = 0.0;
  float s = 10.00;
  float r = 28.00;
  float b =  2.67;
  float dt = 100E-6;
/* graphics' variables/parameters: */
  float xxscale = 0.02*(float)(getmaxx()+1); /* for plot scaling */
  float yyscale = 0.01*(float)(getmaxy()+1); /* for plot scaling */
  WORD xx0 = (getmaxx()+1)/2;     /* plot center x */
  WORD yy0 = (getmaxy()+1)/2;     /* plot center y */
  WORD color = 15;

/* border, x and y axes: */
  setcolor(DARKGRAY);
  rectangle(0,0,getmaxx(),getmaxy());
  line(0,yy0,getmaxx(),yy0); line(xx0,0,xx0,getmaxx());
/* loop: */
  while ( kbhit() ) getch();
  do
  {
    float dx,dy,dz;
    WORD    xx,yy;

    /* put a pixel: */
    xx = xx0+(int)(xxscale*x); yy = yy0-(int)(yyscale*z);
    putpixel(xx,yy,color);
    /* new x,y,z values: */
    dx = dt * (s*(y-x));
    dy = dt * (r*x - y - x*z);
    dz = dt * (x*y - b*z);
    x += dx; y += dy; z += dz;
    /* next color: */
    color++; if ( color > 15 ) color = 0;
  }
  while ( !kbhit() );
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://synth-diy.org/pipermail/synth-diy/attachments/20030704/7f227550/attachment.htm>


More information about the Synth-diy mailing list