xxxxxxxxxx
27
/* My current sketch shows two overlapping red boxes. Pass parameters into the constructor so that the boxes would go next to one another and one would be red and the other would be green as shown in the example image. */
let box1;
let box2;
function setup() {
createCanvas(400, 400);
box1 = new Box(200, color(255, 0, 0));
box2 = new Box(100, color(0,255, 0));
}
function draw() {
background(220);
box1.display();
box2.display();
}
class Box {
constructor(abcX,boxColor){
this.x = abcX;
this.c = boxColor;
}
display(){
fill(this.c);
rect(this.x,50,100,50);
}
}