Changing order of Overlapping Shapes

niftynathan7
Fri, 26 Jul 2024 03:01:11 +0000
Coding Questions

Heya,

I am trying to make the blue rectangle go over the top of the red one without going over the yellow one, I am only allowed to use 4 rectangles. I have tried to do this using PShape but have come up short, was wondering if someone could help me?

PShape RedRect;
PShape BlueRect;

void setup(){
  size(500,500);
BlueRect = createShape(RECT, 100,50,300,100);
RedRect = createShape(RECT,50,100,100,300);
RedRect.setFill(color(255,0,0));
BlueRect.setFill(color(0,0,255));
}

void draw(){
  shape(BlueRect);

  fill(255,255,0);
  rect(350,100,100,300);

  fill(0,255,0);
  rect(100,350,300,100);

  shape(RedRect);
}

7 posts - 4 participants