Initializing stacked circles in setup() vs draw() draws only one circle

Hello,

I added two dimensional arrays to your code with success.

Just enough to get you started:

int div = 8; //# of points around the circle
int numCircs = div-3; //# of loops to draw 4 nested circles
int addPoints = div-5; //# of additional points to complete circle shape

float [][] x = new float [numCircs][div];
float [][] y = new float [numCircs][div];

float cx; // center x of circle
float cy; // center y of circle

float r = 20; // circle radius
float section = radians(360/div);

void setup() {
  size (400, 400);
  cx = width/2;
  cy = height/2;

  noFill();
  stroke(0);

  for (int j = 0; j < numCircs; j++) {
    //beginShape();
    for (int i = 0; i < div; i++) { //plots the curveVertex points around the circle
      float angle = i*section;
      x[j][i] = cx + cos(angle) * r*j; // r*j = increase radius of circle each time
      y[j][i] = cy + sin(angle) * r*j;
    }
    //endShape();
  }
}

void draw() {
  background(255);

// Your code...

}

void update() {
  for (int j = 0; j < 5; j++) {
 
// Your code...
  }  
}

And voila!

image

image

Reference:

:)

2 Likes