All these circles make a square?

I’m probably missing something real basic, but I can’t seem to understand why all my circles seem to make squares.

void draw(){
    fill(255);
    text(this.electrons,this.x+30,this.y);
    fill(0);
    ellipseMode(CENTER);
    ellipse(this.x,this.y,20,20);
    for(int i=0;i<this.electrons;i++){
      float a = random(-20,20);
      float b = random(-20,20);
      fill(0);
      ellipse(this.x+a,this.y+b,5,5);
    }

this is the output

Hello,

Try to isolate and see the outline of the shape first:

    background(0);
    noFill();
    stroke(255, 255, 0);
    strokeWeight(1);
    ellipse(50, 50, 10, 10);

And then try:

    background(0);
    fill(255, 255, 0);
    noStroke();
    ellipse(50, 50, 10, 10);

:slight_smile:

Thanks for your replies guys, I forgot I need to incorporate trig into the positions.

1 Like

Yes, these lines let the circles appear inside a rectangle shape (as circles).

Instead, using trig (Trigonometry), you can have all the circles appear inside a circular shape.

Use a random angle and a random radius.

see

void setup() {
  size(800, 800);
  noStroke();
  ellipseMode(CENTER);
}

void draw() {
  float x=width/2;
  float y=height/2;

  for (int i=0; i<33; i++) {

    float radius = random(0, 200);
    float angle = random(0, TWO_PI);

    fill(random(255), random(255), random(255));

    float a=cos(angle) * radius; 
    float b=sin(angle) * radius;
    ellipse(x+a, y+b, 
      5, 5);
  }
}
2 Likes