-
Notifications
You must be signed in to change notification settings - Fork 0
/
maxify.pde
194 lines (162 loc) · 4.74 KB
/
maxify.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
color skyColor;
int minRays = 10;
int maxRays = 30;
int rayCount;
float rayOffset;
float rayLength = 1200;
color rayColor;
PVector sun;
float minSunRadius = 10;
float maxSunRadius = 150;
float sunRadius;
color sunColor;
int minStars = 10;
int maxStars = 50;
int starCount;
int minStarRadius = 5;
int maxStarRadius = 50;
PVector[] starPositions;
float[] starRadii;
float[] starOffsets;
color starColor;
float minCloudHeight = 50;
float maxCloudHeight = 200;
float maxCloudAngle = .125;
float minCloudRadius = 10;
float maxCloudRadius = 100;
PVector[] cloudPositions;
float[] cloudRadii;
PVector[] cloudCorners;
color cloudColor;
float up = -.25 * TAU;
void setup() {
size(750, 750);
ellipseMode(RADIUS);
strokeJoin(ROUND);
initialize();
}
void mouseClicked() {
initialize();
}
void initialize() {
skyColor = #2090d6;
rayColor = #f24905;
sunColor = #eb9500;
starColor = #eade03;
cloudColor = #f480b7;
rayCount = floor(random(minRays, maxRays + 1) / 2) * 2;
rayOffset = random(0, 1);
sun = new PVector(random(0, width), random(0, height));
sunRadius = random(minSunRadius, maxSunRadius);
starCount = floor(random(minStars, maxStars + 1));
starPositions = new PVector[starCount];
starRadii = new float[starCount];
starOffsets = new float[starCount];
for (int i = 0; i < starCount; i++) {
starRadii[i] = random(minStarRadius, maxStarRadius);
starOffsets[i] = random(0, 1);
starPositions[i] = placeStar(i);
}
placeClouds();
}
void draw() {
background(skyColor);
stroke(0);
strokeWeight(3);
fill(rayColor);
for (float i = 0; i < rayCount; i += 2) {
PVector point1 = pointOnCircle(sun, (i / rayCount + rayOffset) * TAU, rayLength);
PVector point2 = pointOnCircle(sun, ((i + 1) / rayCount + rayOffset) * TAU, rayLength);
triangle(point1, sun, point2);
}
fill(sunColor);
circle(sun, sunRadius);
fill(starColor);
for (int i = 0; i < starCount; i++) {
star(starPositions[i], starRadii[i], starOffsets[i]);
}
clouds();
}
void placeClouds() {
cloudPositions = new PVector[1];
cloudRadii = new float[1];
cloudCorners = new PVector[1];
int i = 0;
cloudPositions[0] = new PVector(-20, height - random(minCloudHeight, maxCloudHeight));
cloudRadii[0] = random(minCloudRadius, maxCloudRadius);
cloudCorners[0] = pointOnCircle(cloudPositions[0], up, cloudRadii[0]);
while (cloudPositions[i].x < width) {
float angle = random(-maxCloudAngle, maxCloudAngle) * TAU;
float radius = random(minCloudRadius, maxCloudRadius);
PVector origin = pointOnCircle(cloudPositions[i], angle, cloudRadii[i] + radius);
cloudPositions = (PVector[])append(cloudPositions, origin);
cloudRadii = append(cloudRadii, radius);
cloudCorners = (PVector[])append(cloudCorners,
pointOnCircle(origin, angle - .5 * TAU, radius));
i += 1;
}
cloudCorners = (PVector[])append(cloudCorners,
pointOnCircle(cloudPositions[i], up, cloudRadii[i]));
}
PVector placeStar(int i) {
PVector star;
boolean sunClear;
boolean starsClear;
int tries = 0;
do {
star = new PVector(random(0, width), random(0, height));
sunClear = dist(star, sun) > (sunRadius + starRadii[i]);
starsClear = true;
if (sunClear) {
for (int j = 0; j < i; j++) {
if (dist(star, starPositions[j]) <= (starRadii[i] + starRadii[j])) {
starsClear = false;
break;
}
}
}
tries += 1;
}
while ((!sunClear || !starsClear) && tries < 100);
return star;
}
void star(PVector origin, float radius, float offset) {
beginShape();
for (float i = 0; i < 5; i++) {
float oa = (i / 5 + offset) * TAU;
float ia = ((i + .5) / 5 + offset) * TAU;
vertex(pointOnCircle(origin, oa, radius));
vertex(pointOnCircle(origin, ia, radius / 2));
}
endShape(CLOSE);
}
PVector pointOnCircle(PVector origin, float angle, float radius) {
return new PVector(origin.x + cos(angle) * radius, origin.y + sin(angle) * radius);
}
void clouds() {
fill(cloudColor);
push();
stroke(cloudColor);
beginShape();
int i;
for (i = 0; i < cloudPositions.length; i++) {
vertex(cloudCorners[i]);
vertex(cloudPositions[i]);
}
vertex(cloudPositions[i - 1].x, height + 10);
vertex(cloudPositions[0].x, height + 10);
endShape();
pop();
for (i = 0; i < cloudPositions.length; i++) {
float left = i == 0 ? up : atan2(
cloudPositions[i - 1].y - cloudPositions[i].y,
cloudPositions[i - 1].x - cloudPositions[i].x);
float right = i == cloudPositions.length - 1 ? up : atan2(
cloudPositions[i + 1].y - cloudPositions[i].y,
cloudPositions[i + 1].x - cloudPositions[i].x);
if (right < left) {
right += TAU;
}
arc(cloudPositions[i].x, cloudPositions[i].y, cloudRadii[i], cloudRadii[i], left, right);
}
}