I am using an Image I drew with a dynamic background colour to simulate day/ night… Depending on the time of day the background colour changes dynamically. What happens is that not only my background changes, but the whole screen blinks every second. Is there a way to avoid this from happening?
My code is the following…
int m = millis();
int sketch_seconds = 0;
String sketch_period = "A";
float b_value = 0;
PImage desert;
void setup(){
//set up the background full screen starting time 6AM
//variable Int b_value;
background(0,27,0);
desert = loadImage("desert_illustrator.png");
//load the mountains and desert image
//set up the two arrows on the watch starting time 6AM
}
void draw(){
//draw the sky colour, B value changes fill(0,0,value), through the day
//6AM to 12AM
image(desert, 0, 0, width, height);
if (millis() > m + 1000){
m = millis();
if (sketch_seconds < 24) {
sketch_period = "A";
println("case A"); }
else if (sketch_seconds < 48) {
sketch_period = "B";
println("case B");}
else if (sketch_seconds < 72) {
sketch_period = "C";
println("case C");}
else if (sketch_seconds < 96) {
sketch_period = "D";
println("case D");}
else if (sketch_seconds < 97) {
sketch_period = "E";
println("case E");}
println("check switch statement");
switch (sketch_period) {
//sun is rising, sky brightens
case "A" :
println("case A");
sketch_seconds = sketch_seconds + 1;
b_value = b_value + (255/24);
background (0,27,b_value);
break;
//sky at its brightest, sun is present and moving
case "B" :
println("case B");
sketch_seconds = sketch_seconds + 1;
b_value = 255;
background (0,27,255);
break;
//sun goes down, moon comes up
case "C" :
println("case C");
sketch_seconds = sketch_seconds + 1;
b_value = b_value - (255/24);
background (0,27,b_value);
break;
//sky at its darkest, moon is present and moving
case "D" :
println("case D");
sketch_seconds = sketch_seconds + 1;
b_value = 0;
background (0,27,0);
break;
//96th second, time to reset some values
case "E" :
println("case E");
sketch_seconds = 0;
break;
}
}
//small arrow on the watch indicates hour, full rotation in 48 seconds
//large arrow on the watch indicates minutes, full rotation in 4 seconds
}