I'm having trouble making the Mandelbrot set

edited December 2017 in Questions about Code

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

Sign In or Register to comment.