-
Notifications
You must be signed in to change notification settings - Fork 0
/
Star.pde
65 lines (59 loc) · 1.84 KB
/
Star.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Star {
int xPos;
int yPos;
//Opacity variable
float currentOpacity; //vary between two values, but don't go invisible.
float opacityDelta; //randomly generate to appear like it's blinking
float upperOpacity; //Upper limit of opacity
float lowerOpacity; //Lower limit of opacity
float targetOpacity;
float minDelta;
float maxDelta;
//Pimage
PImage starImg;
Star(int inpX, int inpY, int inpUOpacity, int inpLOpacity, float inpMinDelta, float inpMaxDelta, PImage inpStarImg) {
xPos = inpX;
yPos = inpY;
starImg = inpStarImg;
minDelta = inpMinDelta;
maxDelta = inpMaxDelta;
opacityDelta = (float)round(random(minDelta, maxDelta));
upperOpacity = inpUOpacity;
lowerOpacity = inpLOpacity;
targetOpacity = (float)round(random(upperOpacity, lowerOpacity));
}
void drawStar(int inpHour, int inpMin) {
pushMatrix();
setOpacity(inpHour, inpMin);
imageMode(CENTER);
tint(255, currentOpacity);
image(starImg, xPos, yPos);
popMatrix();
}
void setOpacity(int inpHour, int inpMin) {
if(inpHour > 5 && inpHour < 19){
if(currentOpacity > 0){
currentOpacity -= opacityDelta;
if(currentOpacity < 0){
currentOpacity = 0;
}
}
}
else{
if(currentOpacity <= targetOpacity){
currentOpacity += opacityDelta;
if(currentOpacity >= targetOpacity){
opacityDelta = (float)round(random(minDelta, maxDelta));
targetOpacity = (float)round(random(lowerOpacity, upperOpacity));
}
}
else if(currentOpacity >= targetOpacity){
currentOpacity -= opacityDelta;
if(currentOpacity <= targetOpacity){
opacityDelta = (float)round(random(minDelta, maxDelta));
targetOpacity = (float)round(random(lowerOpacity, upperOpacity));
}
}
}
}
}