We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm new to programming and I'm trying to make the Mandelbrot set. I am trying to make a nestled loop for the x and y values of the window (corresponding to a and b for the complex number input a + bi ). I want it to create a function for each one that performs the function z^2 + c and changes the color of the point it draws based on how long it took z to get to infinity (16).
int maxIterations = 50;
float infinity = 16;
void setup(){
size(720,720);
background(0);
for(int x = 0; x < width; x++){
for(int y = 0; y<height; y++){
float a = (x-360)/180;
float b = (y-360)/180;
float c = a + b*sqrt(-1);
cSet( c , 0 , 0 , x ,y);
}
}
}
void cSet(float c, float z, int iterations, int x, int y){
if(iterations < maxIterations && z < infinity){
cSet( c , pow(z,2) + c , iterations + 1 , x , y);
}
if(z > infinity){
stroke(iterations*5);
point(x,y);
}
}
Answers
I just happen to have this handy.
That works but I'm more looking to figure out why my code doesn't work. Right now its just a black canvas.
http://Studio.ProcessingTogether.com/sp/pad/export/ro.96P5CDnO6mAXt
Okay so I think the problem has to do with processing not being able to use complex numbers. Anyone know how to fix this?
Java Mode: https://Forum.Processing.org/two/discussions/tagged/complex
Python Mode:
ha ha ha
you have to treat the two parts of the complex number separately. hold them in a pvector or two separate variables.
sqrt(-1) is undefined.