void setup() {
size(500,500);
background(#87ceeb);
fill(#567d46);
rect(0,height/2,500,height/2);
fill(#FFA500);
circle(50,50,75);
// Cloud 1
noStroke();
fill(#FFFFFF);
circle(335,50,50);
circle(300,50,35);
circle(370,50,35);
noStroke();
fill(#FFFFFF);
circle(335,75,50);
circle(300,75,35);
circle(370,75,35);
// Cloud 2
noStroke();
fill(#FFFFFF);
circle(200,50,50);
circle(165,50,35);
circle(235,50,35);
// Bush 1
fill(#112A12);
circle(100,425,50);
circle(65,425,35);
circle(135,425,35);
noStroke();
fill(#112A12);
circle(100,450,50);
circle(65,450,35);
circle(135,450,35);
// Bush 2
fill(#112A12);
circle(400,250,50);
circle(365,250,35);
circle(435,250,35);
noStroke();
// Path
fill(#d9b99b);
rect(0,300,width,75);
// Post
fill(#563d2d);
rect(20,225,35,15);
fill(#5C4033);
rect(50,200,15,100);
fill(#563d2d);
rect(65,210,35,15);
}
void draw() {
if (key == 'n'){
background(#040348);
fill(#006400);
rect(0,height/2,500,height/2);
// Moon
fill(#d3d3d3);
circle(450,50,75);
fill(#808080);
circle(435,35,15);
fill(#808080);
circle(450,65,25);
// Rock
rect(365,190,100,100);
rect(350,280,130,20);
fill(#563d2d);
rect(365,300,100,85);
textSize(35);
fill(#d3d3d3);
text("RIP",390,235);
// Tree
fill(#563d2d);
rect(60,140,75,200);
fill(#154734);
rect(25,150,145,75);
rect(35,125,125,75);
// Stars
fill(#ffff00);
circle(75,50,10);
circle(135,80,10);
circle(225,65,10);
circle(275,200,10);
circle(300,150,10);
circle(330,20,10);
// Path
fill(#AC9362);
rect(0,400,width,75);
} else if (key == 'd') {
background(#87ceeb);
fill(#567d46);
rect(0,height/2,500,height/2);
fill(#FFA500);
circle(50,50,75);
// Cloud 1
noStroke();
fill(#FFFFFF);
circle(335,50,50);
circle(300,50,35);
circle(370,50,35);
noStroke();
fill(#FFFFFF);
circle(335,75,50);
circle(300,75,35);
circle(370,75,35);
// Cloud 2
noStroke();
fill(#FFFFFF);
circle(200,50,50);
circle(165,50,35);
circle(235,50,35);
// Bush 1
fill(#112A12);
circle(100,425,50);
circle(65,425,35);
circle(135,425,35);
noStroke();
fill(#112A12);
circle(100,450,50);
circle(65,450,35);
circle(135,450,35);
// Bush 2
fill(#112A12);
circle(400,250,50);
circle(365,250,35);
circle(435,250,35);
noStroke();
// Path
fill(#d9b99b);
rect(0,300,width,75);
// Post
fill(#563d2d);
rect(20,225,35,15);
fill(#5C4033);
rect(50,200,15,100);
fill(#563d2d);
rect(65,210,35,15);
}
}
void mousePressed() {
fill(#FF0000);
circle(mouseX,mouseY,50);
}
I want to make it so that whenever I click it places an object into the canvas, but whenever I switch between day and night and return, the circles dispear. On top of that, I can only place circles before I switch between day and night. Swithcing causes the next circles being placed to dispear immidetaly. How can I fix these issues.
I tried to placing the void mousepressed function inside the loop, however that did nto work either.
remember that each time the draw function is called (60 times per secon i think), everything disapears since you call
background()that's why you need to draw your circles again.To overcome that problem you could store the coordinates of your circles in an array and then draw from those coordinates. For example you can create an IntList for the x voordinates and add mouseX to it each time the mouse is pressed and do the same for the y coodrinates, then go over your lists and call
circle(x,y,50)for each coordinate.