 |
Author |
Topic: real-time mandelbrot set (works) (Read 713 times) |
|
mm Guest

|
real-time mandelbrot set (works)
« on: Mar 21st, 2004, 10:34pm » |
|
http://www.madmerv.com/proce55ing/mandelbrot Code: /* Mandelbrot.java - Java Mandelbrot by MN Karthik. Any questions, comments, suggestions? You can contact me at mnkarthik@yahoo.com. Modifications and adaptation to Processing by Mad Merv 2004 http://www.madmerv.com */ void setup() { size(320,320); background(0); stroke(0); fill(0); } void loop() { int sx=width; //Screenwidth int sy=height; //Screenheight double xmin=-2; //smallest real value (x-axis) double xmax=1.25; //largest real value (x-axis) double ymin=-1.25; //smallest imaginary value (y-axis) double ymax=1.25; //largest imaginary value (y-axis) double maxiter=512; //Max number of iterations double old_x; //temporary variable to store x-value double fx,fy; int m; //variable to store number of iterations double dx=(xmax-xmin)/sx; //how much to add for each x-pixel? double dy=(ymax-ymin)/sy; //how much to add for each y-pixel? int px; //Variable storing current x-pixel int py=0; //Variable storing current y-pixel double x; //Variable storing current x-value double y=ymin; //Variable storing current y-value stroke(0); while (py<sy) { px=0; x=xmin; py++; while (px<sx) { px++; fx=0; fy=0; m=0; do { old_x=fx; fx=fx*fx-fy*fy+x; fy=2*old_x*fy+y; m++; } while (((fx*fx+fy*fy)<4) && (m<maxiter)); /* if (m%2==0) stroke(255,200,125); if (m%3==0) stroke(250,100,125); if (m%4==0) stroke(245,90,125); if (m%5==0) stroke(240,80,125); if (m%6==0) stroke(235,70,125); if (m%7==0) stroke(230,60,125); if (m%8==0) stroke(200,50,125); if (m%9==0) stroke(180,40,125); if (m%10==0) stroke(100,30,125); if (m%11==0) stroke(50,20,125); if (m%12==0) stroke(20,10,125); if (m%13==0) stroke(0); */ stroke(m%50+((mouseX+mouseY)/2),m%12*(255/12),m%4*(255/4)); line(px-3,py-3,px+10,py+10); //the +10 adds a nice effect while rendering :) x+=dx; } y+=dy; } } |
|
|
|
|
|
|