Created
March 30, 2016 17:40
-
-
Save ajsdo222/a43233dc1402d6582109fa9a24a42e7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float b = 80; | |
int time = 0; // default time | |
int sunrise_time = 6; // the time when the sun is coming up | |
int sunset_time = 17; // the time when the sun goes down | |
boolean sunrise = false; // check sunset, and sunrise | |
boolean sunset = false; | |
boolean AMPM = false; // check if the time is AM or PM | |
boolean cloudy = false; | |
void setup() | |
{ | |
size(500,500); | |
} | |
void draw() | |
{ | |
println("current time is :"+time+":00",sunrise); | |
AMPM_Checker(); | |
Sunrise_Checker(); | |
Sunset_Checker(); | |
if(!cloudy) | |
{ | |
if(!sunrise && !sunset )background(0,b-80,b); | |
else if(sunrise && !sunset)background(255,b,0); | |
else if(!sunrise && sunset)background(255,b-80,0); | |
else if(!sunrise && !sunset)background(0,b-80,b); | |
} | |
else | |
{ | |
background(b); | |
} | |
} | |
void Sunrise_Checker() | |
{ | |
if(sunrise_time == time && abs(sunrise_time - time)<=5) | |
{ | |
sunrise = true; | |
} | |
if(sunrise && abs(sunrise_time - time)>5) | |
{ | |
sunrise = false; | |
} | |
} | |
void Sunset_Checker() | |
{ | |
if(sunset_time == time && abs(sunset_time - time)<=3) | |
{ | |
sunset = true; | |
} | |
if(sunset && abs(sunset_time - time)>3) | |
{ | |
sunset = false; | |
} | |
} | |
void AMPM_Checker() | |
{ | |
if(time>=12)AMPM = true; | |
if(time<12)AMPM = false; | |
if(AMPM == false) | |
{ | |
b = map(time%12,0,12,80,255); // map the value 0 - 12 to 80 - 255 | |
} | |
else if(AMPM == true) | |
{ | |
b = map(time%12,1,12,255,80); // map the value 0 - 12 to 255 - 80 (reverse) | |
} | |
} | |
void keyPressed() | |
{ | |
if(key == '1' && time < 23) time++; | |
if(key == '2' && time > 0) time--; | |
if(key == '3') cloudy = true; | |
if(key == '4') cloudy = false; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment