-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStar.pde
More file actions
117 lines (109 loc) · 3.25 KB
/
Copy pathStar.pde
File metadata and controls
117 lines (109 loc) · 3.25 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
class Star extends Planet {
boolean supernovaStarted = false;
SupernovaStage stage = SupernovaStage.STABLE;
float stageStartedTime = 0;
float stageElapsedTime = 0;
color previousColor;
float previousSize;
color sunStroke = color(0);
Star(PVector position, float size, float mass, color planetColor) {
super(position, size, new PVector(0, 0), mass, planetColor, false);
previousColor = planetColor;
previousSize = size;
}
void startSupernova() {
supernovaStarted = true;
}
void drawPlanet() {
pushMatrix();
translate(location.x, location.y);
fill(planetColor);
if (sunStroke != color(0)) {
stroke(sunStroke);
strokeWeight(2);
}
circle(0, 0, size);
noStroke();
popMatrix();
}
void handleSupernova() {
stageElapsedTime = frameCount - stageStartedTime;
switch(this.stage) {
case STABLE:
stage = SupernovaStage.GROWING;
stageStartedTime = frameCount;
supernovaTooltip = stage;
break;
case GROWING:
if (stageElapsedTime < stage.duration) {
size = map(stageElapsedTime, 0, stage.duration, previousSize, shorterScreenEdgeLength - shorterScreenEdgeLength/40);
planetColor = lerpColor(previousColor, color(255, 0, 0), stageElapsedTime / stage.duration);
} else {
stage = SupernovaStage.GIANT;
stageStartedTime = frameCount;
supernovaTooltip = stage;
}
break;
case GIANT:
if (stageElapsedTime > stage.duration) {
stage = SupernovaStage.COLLAPSE;
stageStartedTime = frameCount;
previousColor = planetColor;
previousSize = size;
supernovaTooltip = stage;
}
break;
case COLLAPSE:
if (stageElapsedTime < stage.duration) {
size = map(stageElapsedTime, 0, stage.duration, previousSize, 10);
planetColor = lerpColor(previousColor, color(255, 255, 255), stageElapsedTime / stage.duration);
} else {
stage = SupernovaStage.EXPLOSION;
stageStartedTime = frameCount;
previousSize = size;
supernovaTooltip = stage;
}
break;
case EXPLOSION:
if (stageElapsedTime < stage.duration) {
size = map(stageElapsedTime, 0, stage.duration, previousSize, (width + height - shorterScreenEdgeLength) * 1.2);
} else {
stage = SupernovaStage.FADING;
stageStartedTime = frameCount;
previousColor = planetColor;
previousSize = size;
supernovaTooltip = stage;
}
break;
case FADING:
if (stageElapsedTime < stage.duration) {
fill(lerpColor(previousColor, color(255, 255, 255, 0), stageElapsedTime / stage.duration));
circle(location.x, location.y, previousSize);
} else {
stage = SupernovaStage.FINAL;
supernovaTooltip = stage;
}
size = shorterScreenEdgeLength / 20;
planetColor = color(0);
sunStroke = color(255, 180, 0, 100);
strokeWeight(60);
break;
case FINAL:
supernovaStarted = false;
break;
}
}
}
enum SupernovaStage {
STABLE(0),
GROWING(1200),
GIANT(1200),
COLLAPSE(300),
EXPLOSION(180),
FADING(180),
FINAL(0);
public final float duration;
SupernovaStage(float duration) {
this.duration = duration;
}
}