FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Simulation, Artificial Life
(Moderator: REAS)
   mandelbrot set
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: mandelbrot set  (Read 908 times)
wwwww
Guest
Email
mandelbrot set
« on: Oct 19th, 2002, 4:19pm »

// simple mandelbrot set
// by william
 
 
int W = 300;
int H = 300;
 
 
void setup()
{
  size(W, H);
}
 
 
 
void loop()
{
 
  float zoom = 100.0;
  float offset = 50.0;
 
  float re, im;
  float co; // counter
  int accuracy = 50;
 
  for (int i=0; i<W; i++) {
    for (int j=0; j<H; j++) {
 
 // for every point on complex plane    
 re = (i-offset)/zoom - W/2/zoom;
 im = j/zoom - H/2/zoom;
 
 //complex number z, c
 float[] z = {0,0};
 float[] c = {re, im};
 
 co = 0;  
 
 for (int k=0; k<accuracy; k++) {
   //z(next) = z*z + c;
 
   float[] zz = { (sq(z[0]) - sq(z[1]) + re), (2*z[0]*z[1] + im) };
 
   z = zz;
 
   // check if the modulus of complex num is within limit
 
   if ( sqrt((sq(z[0]) + sq(z[1])) )>2 ) {
     co = 1 - k/float(accuracy);
     break;
   }
 
 }
 
 
 setPixel( i, j, color(200*co, 200*co, 200*co) ); //gray colouring scheme
 
 //setPixel( i, j, int( 16777215*co ) ); //"funky" colouring scheme
   
 
    }
  }
 
}
 
Pages: 1 

« Previous topic | Next topic »