I need random shapes to appear in a random order

Hi everyone

For an assignment I am trying to make two shapes (ellipse and rectangle) appear in a random order (with random color and position).

The color and position I got down, but I cannot seem to seperate the ellipse and the rectangle. Now they appear at the same time. But I don’t want that, I want one or the other, chosen randomly which one.

I am a really beginner so there might be an easy solution but I cannot seem to figure it out!

My code:

float x;
float y;
float w;
float h;  
  
void setup() {
 size(1920, 1080);
 background(255);
 frameRate(10);
 noStroke();
}

void shape() {

  for (int i=0; i<1; i=i+1) { 
    x = int(random(width));
    y = int(random(height));
    w = int(random(50, 200));
    h = int(random(50, 200));
  }
 
 ellipse(x, y, w, h); 
 fill(random(255), random(255), random(255));

 rect(x, y, w, h);
 fill(random(255), random(255), random(255));
}

void draw() {
 random(ellipse, rect);
}

Obviously the last part doesn’t work, but I cannot understand how else I can do it! I appriciate every reply, thank you!

the simplest way to separate the appearance of the two shapes, you could do something like

int scenario = round(random(1)); //either 0 or 1
int x = 20, y = 20, a = 15, x2 = 100, y2 = 100, a2 = 20;
void setup() {
  size(200,200);
}
void draw() {
  if (scenario == 0) {
    if (frameCount>20) circle(x, y, a);
    if (frameCount>50) square(x2, y2, a2);
  } else if (scenario == 1) {
    if (frameCount>20) square(x, y, a);
    if (frameCount>50) circle(x2, y2, a2);
  }
}

Try to do something similar.

At first, you choose which scenario appears at first. Either the square or the circle.
After that, you wait 20 frames for the first shape to appear.
After 50 frames has passed, the second shape will appear.

Hello @maroslan,

Your code with a modification:

float x;
float y;
float w;
float h;

void setup() {
  size(1920, 1080);
  background(255);
  frameRate(10);
  noStroke();
}

void shape() {

  for (int i=0; i<1; i=i+1) {
    x = int(random(width));
    y = int(random(height));
    w = int(random(50, 200));
    h = int(random(50, 200));
  }

  ellipse(x, y, w, h);
  fill(random(255), random(255), random(255));

  rect(x, y, w, h);
  fill(random(255), random(255), random(255));
}

void draw() {
  //random(ellipse, rect);
  shape();
}

Does this:

It still needs work…

Check out the resources here:

:)