Trying to make a smoother oscillation.
in
Programming Questions
•
2 years ago
I have a day/night cycle in my sketch that sets the overall ambient light within a looping animation based on the postion of the sun and moon within the sky by setting the alpha of a rectangle that covers the width and height of the sketch. My day cycle works perfectly fine because the alpha ranges between 0 and 220, but my night cycle only ranges between 190 and 220 and looks choppier which I suspect has to do with the way i calculate the alpha value.
Suggestions?
- void ambient_light_cycle() {
- //Calculates the position of the current day/night cycle;
- float light_position = angle % TWO_PI;
- float light_alpha = 220;
- //Sun starts on horizon and peaks at HALF_PI
- //Moon enters horizon at PI and peaks PI + HALF_PI
- if(light_position <= HALF_PI) {
- light_alpha = 220 - ((220/HALF_PI) * (light_position % HALF_PI));
- } else if (light_position <= PI && light_position > HALF_PI) {
- light_alpha = (220/HALF_PI) * (light_position % HALF_PI);
- } else if(light_position > PI && light_position <= (PI + HALF_PI)) {
- light_alpha = 220 - ((30/HALF_PI) * (light_position % HALF_PI));
- } else if(light_position > (PI + HALF_PI) && light_position <= TWO_PI) {
- light_alpha = 190 + ((30/HALF_PI) * (light_position % HALF_PI));
- }
- fill(0, light_alpha);
- rect(0,0,width,height);
- }
Suggestions?
1