Working on a project and I have a few questions before it’s complete. First, on the third stage of my code it is snowing, but when I went to go use the same code I made for rain on my fourth stage the rain is not moving. (Also, is there a way to simplify the rain and snow function to make random circles?) Third question is I’m trying to make the windows slowly change color but when I use random in fill() it was changing too fast so I slowed down the frame rate but that caused the whole code to slow down, is there any way to slow down the changing lights without slowing down the rest of the code? Thanks!
//variables
float time=0;//for wave animation
float[]a=new float[2000];//star posx array
int stage;//season stages
float car;//car
float circleX;
float circleXr;
float snow;//snow
float rain;//rain
//float window;//windows
PImage start;
wall[]walls;//windows
void setup(){
size(1000,700);
start=loadImage("start.jpg");
circleX=0;
snow=1;
//windows setup
walls=new wall[71];//creates an array(list) for the windows array starts at 0
walls[0]=new wall(470,300,20,20);
walls[1]=new wall(510,300,20,20);
walls[2]=new wall(470,340,20,20);
walls[3]=new wall(510,340,20,20);
walls[4]=new wall(470,380,20,20);
walls[5]=new wall(510,380,20,20);
walls[6]=new wall(470,420,20,20);
walls[7]=new wall(510,420,20,20);
walls[8]=new wall(470,460,20,20);
walls[9]=new wall(510,460,20,20);
walls[10]=new wall(470,500,20,20);
walls[11]=new wall(510,500,20,20);
walls[12]=new wall(470,540,20,20);
walls[13]=new wall(510,540,20,20);
walls[14]=new wall(770,300,20,20);
walls[15]=new wall(810,300,20,20);
walls[16]=new wall(770,340,20,20);
walls[17]=new wall(810,340,20,20);
walls[18]=new wall(770,380,20,20);
walls[19]=new wall(810,380,20,20);
walls[20]=new wall(770,420,20,20);
walls[21]=new wall(810,420,20,20);
walls[22]=new wall(770,460,20,20);
walls[23]=new wall(810,460,20,20);
walls[24]=new wall(770,500,20,20);
walls[25]=new wall(810,500,20,20);
walls[26]=new wall(770,540,20,20);
walls[27]=new wall(810,540,20,20);
walls[28]=new wall(870,340,20,20);
walls[29]=new wall(915,380,20,20);
walls[30]=new wall(960,380,20,20);
walls[31]=new wall(870,380,20,20);
walls[32]=new wall(915,420,20,20);
walls[33]=new wall(960,420,20,20);
walls[34]=new wall(870,420,20,20);
walls[35]=new wall(915,460,20,20);
walls[36]=new wall(960,460,20,20);
walls[37]=new wall(870,460,20,20);
walls[38]=new wall(915,340,20,20);
walls[39]=new wall(960,340,20,20);
walls[40]=new wall(960,500,20,20);
walls[41]=new wall(915,500,20,20);
walls[42]=new wall(870,500,20,20);
walls[43]=new wall(960,540,20,20);
walls[44]=new wall(915,540,20,20);
walls[45]=new wall(870,540,20,20);
walls[46]=new wall(15,300,20,20);
walls[47]=new wall(55,340,20,20);
walls[48]=new wall(15,340,20,20);
walls[49]=new wall(55,380,20,20);
walls[50]=new wall(15,380,20,20);
walls[51]=new wall(55,420,20,20);
walls[52]=new wall(15,420,20,20);
walls[53]=new wall(55,460,20,20);
walls[54]=new wall(15,460,20,20);
walls[55]=new wall(55,500,20,20);
walls[56]=new wall(15,500,20,20);
walls[57]=new wall(55,540,20,20);
walls[58]=new wall(15,540,20,20);
walls[59]=new wall(55,340,20,20);
walls[60]=new wall(55,300,20,20);
walls[61]=new wall(110,370,20,20);
walls[62]=new wall(155,370,20,20);
walls[63]=new wall(110,410,20,20);
walls[64]=new wall(155,410,20,20);
walls[65]=new wall(110,450,20,20);
walls[66]=new wall(155,450,20,20);
walls[67]=new wall(110,490,20,20);
walls[68]=new wall(155,490,20,20);
walls[69]=new wall(110,530,20,20);
walls[70]=new wall(155,530,20,20);
snow();
rain();
draw_windows();
make_stars();
}
void draw() {
//stage 1=night time
if (keyPressed){
if (key=='1'){
stage=1;
}}
if(stage==1);{
background(43,47,119);
noStroke();
moon();//moon goes first to see stars on the cutout
draw_stars();
building();
draw_windows();//windows not walls (fix name of class)
car();
bridge();
draw_wave();//last so it is over bottom of buildings
//if key 2 is pressed stage=2
if (keyPressed){
if (key=='2'){
stage=2;
}}
if (keyPressed){
if (key=='3'){
stage=3;
}}
if (keyPressed){
if (key=='4'){
stage=4;
}}
if (keyPressed){
if (key=='5'){
stage=5;
}}}
//stage 2=day time
if (stage==2){
background(116,mouseY,mouseX);
noStroke();
draw_sun();
building_stage2();
draw_windows();
car();
bridge();
draw_wave2();
if (keyPressed){
if (key=='3'){
stage=3;
}}
if (keyPressed){
if (key=='5'){
stage=5;
}}}
//stage 3=winter
if (stage==3){
background(116,204,244);
noStroke();
building_stage2();
draw_windows();
car();
bridge();
draw_wave3();
snow();
if (keyPressed){
if (key=='4'){
stage=4;
}}
if (keyPressed){
if (key=='5'){
stage=5;
}}}
//stage 4=rain
if (stage==4){
background(43,47,119);
noStroke();
building();
draw_windows();//windows not walls (fix name of class)
car();
bridge();
draw_wave4();//last so it is over bottom of buildings
rain();
if (keyPressed){
if (key=='5'){
stage=5;
}}}
if (stage==5){
background(255);
//image(start,0,0,1000,700);
textSize(30);
text("Instructions",380,30);
//text("Press 1 for Night time",
}
}
void car(){
car=car+1;
if (car>= width+100){
car=0;
}
fill(192,192,192);
rect(car,460,30,20);
rect(car-120,460,30,20);
rect(car-300,460,30,20);
}
void moon(){
fill(254,252,215);
noStroke();
ellipse(900,100,150,150);
noStroke();
fill(43,47,119);
ellipse(880,90,125,125);
}
void building(){
noStroke();
fill(0,0,80);
rect(450,280,100,350);//middle building
rect(465,220,70,60);//"
rect(479,200,40,20);//"
rect(496,170,5,30); //"
rect(850,320,300,300);//far right building
rect(750,280,100,350);//second one from the right
rect(0,280,100,350);//far left building
rect(100,350,100,300);//second from the left building
}
void building_stage2() {
noStroke();
fill(102,120,127);
rect(450,280,100,350);
rect(465,220,70,60);
rect(479,200,40,20);
rect(496,170,5,30);
rect(850,320,300,300);
rect(750,280,100,350);
rect(0,280,100,350);
rect(100,350,100,300);
}
void bridge() {
//bridge
stroke(0);
for (int i=0; i<1000; i=i+10) {
line(i,440,i,480);
}
fill(0);
rect(0,440,1000,10);
rect(0,480,1000,20);
}
//
void make_stars(){
for (int i=0; i<a.length;i++) a[i]=random(0,1700);
}
void draw_stars(){
fill(255,255,255);
for (int i=0;i<a.length; i++) ellipse(a[i],i*0.4,2,2);
}
void draw_wave() {
float x=0;
stroke(0);
while(x<width){
line(x,520+50*noise(x/100,time),x,height);
x=x+1;
}
time=time+0.01;
}
void draw_wave2(){
float x=0;
stroke(15,94,156);
while(x<width){
line(x,520+50*noise(x/100,time),x,height);
x=x+1;
}
time=time+0.01;
}
void draw_wave3(){
fill(255);
noStroke();
rect(0,530,1000,1000);
}
void draw_wave4(){
float x=0;
stroke(0);
while(x<width){
line(x,450+200*noise(x/100,time),x,height);
x=x+1;
}
time=time+0.01;
}
void draw_sun(){
noStroke();
fill(805,140,0);
ellipse(850,110,100,100);
fill(805,165,0,90);
ellipse(850,110,170,170);
fill(805,165,0,60);
ellipse(850,110,200,200);
}
class wall {
float x;
float y;
float w;
float h;
wall(float x1,float y1,float w1,float h1){
x = x1;
y = y1;
w = w1;
h = h1;
}
//draws the windows
void draw(){
noStroke();
//frameRate(2);
fill(255,255,224);
rect(x,y,w,h);
}
}
void draw_windows(){
//windows
for (int i=0;i<walls.length;i++){
walls[i].draw();
}
}
void snow(){
circleX=circleX+snow;
if (circleX>=width){
circleX=0;
}
fill(255,150);
ellipse(10,circleX,10,10);
ellipse(50,circleX+20,10,10);
ellipse(80,circleX,5,5);
ellipse(110,circleX+100,5,5);
ellipse(140,circleX+150,10,10);
ellipse(180,circleX-200,10,10);
ellipse(200,circleX-150,5,5);
ellipse(240,circleX-50,5,5);
ellipse(240,circleX,10,10);
ellipse(300,circleX+20,5,5);
ellipse(440,circleX,10,10);
ellipse(440,circleX,10,10);
ellipse(550,circleX+100,10,10);
ellipse(530,circleX-250,10,10);
ellipse(530,circleX-200,5,5);
ellipse(580,circleX-300,5,5);
ellipse(300,circleX-400,5,5);
ellipse(140,circleX-350,5,5);
ellipse(400,circleX-300,5,5);
ellipse(550,circleX,5,5);
ellipse(800,circleX,5,5);
ellipse(600,circleX,5,5);
ellipse(700,circleX,5,5);
ellipse(900,circleX,5,5);
ellipse(70,circleX-300,5,5);
ellipse(800,circleX-400,5,5);
ellipse(940,circleX-350,5,5);
ellipse(600,circleX-300,5,5);
ellipse(600,circleX,10,10);
ellipse(700,circleX+20,10,10);
ellipse(600,circleX,5,5);
ellipse(710,circleX+100,5,5);
ellipse(840,circleX+150,10,10);
ellipse(880,circleX-200,10,10);
ellipse(600,circleX-150,5,5);
ellipse(740,circleX-50,5,5);
ellipse(640,circleX,10,10);
ellipse(810,circleX+20,5,5);
ellipse(640,circleX,10,10);
ellipse(740,circleX,10,10);
ellipse(550,circleX+100,10,10);
ellipse(630,circleX-250,10,10);
}
void rain(){
circleX=circleX+rain;
if (circleX>=width){
circleX=0;
}
fill(255,150);
ellipse(10,circleX,10,10);
ellipse(50,circleX+20,10,10);
ellipse(80,circleX,5,5);
ellipse(110,circleX+100,5,5);
ellipse(140,circleX+150,10,10);
ellipse(180,circleX-200,10,10);
ellipse(200,circleX-150,5,5);
ellipse(240,circleX-50,5,5);
ellipse(240,circleX,10,10);
ellipse(300,circleX+20,5,5);
ellipse(440,circleX,10,10);
ellipse(440,circleX,10,10);
ellipse(550,circleX+100,10,10);
ellipse(530,circleX-250,10,10);
ellipse(530,circleX-200,5,5);
ellipse(580,circleX-300,5,5);
ellipse(300,circleX-400,5,5);
ellipse(140,circleX-350,5,5);
ellipse(400,circleX-300,5,5);
ellipse(550,circleX,5,5);
ellipse(800,circleX,5,5);
ellipse(600,circleX,5,5);
ellipse(700,circleX,5,5);
ellipse(900,circleX,5,5);
ellipse(70,circleX-300,5,5);
ellipse(800,circleX-400,5,5);
ellipse(940,circleX-350,5,5);
ellipse(600,circleX-300,5,5);
ellipse(600,circleX,10,10);
ellipse(700,circleX+20,10,10);
ellipse(600,circleX,5,5);
ellipse(710,circleX+100,5,5);
ellipse(840,circleX+150,10,10);
ellipse(880,circleX-200,10,10);
ellipse(600,circleX-150,5,5);
ellipse(740,circleX-50,5,5);
ellipse(640,circleX,10,10);
ellipse(810,circleX+20,5,5);
ellipse(640,circleX,10,10);
ellipse(740,circleX,10,10);
ellipse(550,circleX+100,10,10);
ellipse(630,circleX-250,10,10);
}