-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStarField.pde
79 lines (64 loc) · 1.45 KB
/
StarField.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
public class StarField implements Entity {
private Graphics graphics;
private final int numberOfStars = 30;
private LittleStar[] stars;
public StarField(Graphics graphics_) {
graphics = graphics_;
stars = new LittleStar[numberOfStars];
for (int i = 0; i < numberOfStars; ++i) {
stars[i] = new LittleStar();
}
graphics.setStarField(stars);
}
void setupGrowingState(long duration_) {
}
void drawGrowingState(long time) {
for (int i = 0; i < numberOfStars; ++i) {
stars[i].advance();
}
}
void setupFlashUpState(long duration_) {
}
void drawFlashUpState(long time) {
for (int i = 0; i < numberOfStars; ++i) {
stars[i].advance();
}
}
void setupFlashDownState(long duration_) {
}
void drawFlashDownState(long time) {
for (int i = 0; i < numberOfStars; ++i) {
stars[i].advance();
}
}
}
public class LittleStar {
private int x_, y_, maxSize, state;
private final int maxMaxSize = 5;
private void randomize() {
x_ = int(random(2 * SIZE));
y_ = int(random(2 * SIZE));
maxSize = 1 + int(random(maxMaxSize - 1));
state = 0;
}
public LittleStar() {
randomize();
}
void advance() {
if (millis() % 5 == 0) {
++state;
}
if (state > 2 * maxSize + 1) {
randomize();
}
}
public int x() {
return x_;
}
public int y() {
return y_;
}
public int size() {
return max(0, maxSize - abs(maxSize - state));
}
}