-
Notifications
You must be signed in to change notification settings - Fork 0
/
Star.pde
46 lines (43 loc) · 908 Bytes
/
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
class Star {
int id;
float alpha;
float speed;
boolean increaseFlag; // whether to increase alpha or not
PImage myStar;
Star(int _id) {
id=_id;
speed=random(0.5, 0.7)*3; // the speed of blinking star
myStar=loadImage("img/star"+id+".png");
int tmp=(int)random(0, 2);
if (tmp==1) {
increaseFlag=true;
alpha=0;
} else {
increaseFlag=false;
alpha=255;
}
}
void starDraw() {
blinking();
tint(255, alpha);
imageMode(CORNER);
image(myStar,0,0);
noTint();
// tint(255, 0); // prevent affecting other pictures
}
void blinking() {
if (increaseFlag) {
alpha+=speed;
if (alpha>255) {
alpha=255;
increaseFlag=false;
}
} else {
alpha-=speed;
if (alpha<=0) {
alpha=0;
increaseFlag=true;
}
}
}
}