-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackground.pde
More file actions
362 lines (327 loc) · 9.78 KB
/
Copy pathBackground.pde
File metadata and controls
362 lines (327 loc) · 9.78 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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
class Background {
//Weather Objects
Rain rain;
Clouds cloud;
Sun sun;
Moon moon;
//Background Props
Ground ground;
Sky sky;
//Entities
Entities entityHandler;
ListHandler listHandler;
//JSON objects
JSONObject jsonWeatherData;
JSONObject rainData;
JSONObject cloudData;
//Object Flags
boolean drawRain = true;
boolean drawCloud = true;
boolean drawThunder = true;
boolean drawInstructions = false;
boolean drawSun = true;
boolean drawGround = true;
boolean drawSky = true;
boolean drawStars = true;
boolean drawMoon = true;
//Other Vars
int cloudDensity;
float rainfallMM;
Background() {
jsonWeatherData = loadJSONObject("http://api.openweathermap.org/data/2.5/weather?q=Sydney,AU&appid=93af9bf890724d81ecaa676f91053303&units=metric");
try { //retrieve rain data from json object
rainData = jsonWeatherData.getJSONObject("rain");
rainfallMM = rainData.getFloat("3h") * 10;
println("rainDensity" + rainfallMM);
}
catch(Exception e) {
rainData = null;
rainfallMM = 0.0;
}
try { //retrieve cloud data from json object
cloudData = jsonWeatherData.getJSONObject("clouds");
cloudDensity = cloudData.getInt("all")/2;
println("cloudDensity" + cloudDensity);
}
catch(Exception e) {
cloudData = null;
cloudDensity = 2;
}
//Prepare objects
rain = new Rain((int)rainfallMM, 240, 15, 30);
cloud = new Clouds(cloudDensity, 0.2, 100);
sun = new Sun(240, 150);
ground = new Ground(0, 240, color(133, 168, 74), color(1, 92, 59));
sky = new Sky(color(135, 206, 235), color(15, 15, 66), color(255, 149, 6), color(255, 97, 100), (int)random(80, 150));
entityHandler = new Entities();
moon = new Moon(100);
//UILIST stuff
ArrayList<String> weatherList = new ArrayList<String>();
weatherList.add("Weather");
weatherList.add("Turn on/off rain");
weatherList.add("Turn on/off clouds");
weatherList.add("Manual/Auto sun switch");
weatherList.add("Turn on/off stars");
weatherList.add("Turn on/off sun");
weatherList.add("Turn on/off moon");
listHandler = new ListHandler(weatherList, 50, 50);
//Rain
ArrayList<String> rainList = new ArrayList<String>();
rainList.add("Rain: (" + rain.getRainPrecip() + "mm)");
rainList.add("Add 10mm rain");
rainList.add("Add 100mm rain");
rainList.add("Remove 10mm rain");
rainList.add("Remove 100mm rain");
listHandler.addList(rainList);
//Cloud
ArrayList<String> cloudList = new ArrayList<String>();
cloudList.add("Cloud: (" + cloud.getCloudDensity() + "%)");
cloudList.add("Add 5% cloud");
cloudList.add("Add 100% cloud");
cloudList.add("Remove 5% cloud");
cloudList.add("Remove 100% cloud");
listHandler.addList(cloudList);
//Time
ArrayList<String> timeList = new ArrayList<String>();
timeList.add("Time: (" + sun.currentTime() + ")" + "(" + autoString() +")");
timeList.add("Add 1 hour");
timeList.add("Go back 1 hour");
listHandler.addList(timeList);
//Sky
ArrayList<String> starsList = new ArrayList<String>();
starsList.add("Star: (" + sky.starDensity() + ")");
starsList.add("Add 10 stars");
starsList.add("Remove 10 stars");
listHandler.addList(starsList);
//Volume
ArrayList<String> volumeList = new ArrayList<String>();
volumeList.add("Volume limit: (" + entityHandler.volumeLimit + ")");
volumeList.add("Increase limit");
volumeList.add("Reduce limit");
volumeList.add("Reset limit");
listHandler.addList(volumeList);
}
void drawBackground() {
//Draw Sky
if (drawSky) {
sky.calculateSkyColour(sun.calculateMinutes(sun.getCurrentHour(), sun.getCurrentMinute()));
sky.drawSky(sun.getCurrentHour(), sun.getCurrentMinute(), drawStars);
}
//Draw Sun
if (drawSun) {
sun.drawSun();
}
if(drawMoon){
moon.drawMoon(sun.getCurrentHour(), sun.getCurrentMinute());
}
//Draw Ground
if (drawGround) {
ground.calculateGroundColour(sun.calculateMinutes(sun.getCurrentHour(), sun.getCurrentMinute()));
ground.drawGround();
}
//Draw entities
entityHandler.drawEntities();
//draw rain
if (drawRain) {
rain.drawRain();
listHandler.lists.get(1).modifyListHeader("Rain: (" + rain.getRainPrecip() + "mm)");
}
//Draw clouds
if (drawCloud) {
//draw Clouds
cloud.drawClouds();
listHandler.lists.get(2).modifyListHeader("Cloud: (" + cloud.getCloudDensity() + "%)");
}
//Draw Thunder
if (drawThunder) {
//draw Thunder
}
//DrawUI
listHandler.lists.get(3).modifyListHeader("Time: (" + sun.currentTime() + ")" + "(" + autoString() +")");
listHandler.drawLists();
//Draw Instructions
if (drawInstructions) {
pushMatrix();
fill(255, 255, 255);
String s = "Press 'c' to draw clouds \nPress 'r' to draw rain \nPress 't' to draw thunder \nPress 's' to draw the sun \nPress 'a' to automate the sun movement \nPress '[' to move time back \nPress ']' to move time forward \nPress '=' to increase rain precipitation \nPress '-' to decrease rain precipitation \nPress 'i' to open and close these instructions";
String s2 = "\nCurrent Rainfall: " + rain.getRainPrecip() + "mm";
String s3 = "\nCurrent Cloud density: " + cloud.getCloudDensity() + "%";
String s4 = "\nCurrent Time: " + sun.currentTime();
String s5 = "\nAuto mode Active?: " + sun.autoSunMovement;
text(s + s2 + s3 + s4 + s5, 10, 20);
popMatrix();
}
}
void mouseClickedBackground() {
String uiClicked = listHandler.checkCollision();
//do stuff based on what string they clicked.
//WEATHER
if(uiClicked == "Turn on/off rain"){
//switch rain
setRain();
}
else if(uiClicked == "Turn on/off clouds"){
setClouds();
}
else if(uiClicked == "Manual/Auto sun switch"){
autoSun();
}
else if(uiClicked == "Turn on/off stars"){
setStars();
}
else if(uiClicked == "Turn on/off sun"){
setSun();
}
else if(uiClicked == "Turn on/off moon"){
setMoon();
}
//RAIN
else if(uiClicked == "Add 10mm rain"){
for(int i = 0; i < 10; i++){
increaseRain();
}
}
else if(uiClicked == "Add 100mm rain"){
for(int i = 0; i < 100; i++){
increaseRain();
}
}
else if(uiClicked == "Remove 10mm rain"){
for(int i = 0; i < 10; i++){
decreaseRain();
}
}
else if(uiClicked == "Remove 100mm rain"){
for(int i = 0; i < 100; i++){
decreaseRain();
}
}
//Clouds
else if(uiClicked == "Add 5% cloud"){
for(int i = 0; i < 5; i++){
increaseCloud();
}
}
else if(uiClicked == "Add 100% cloud"){
for(int i = 0; i < 100; i++){
increaseCloud();
}
}
else if(uiClicked == "Remove 5% cloud"){
for(int i = 0; i < 5; i++){
decreaseCloud();
}
}
else if(uiClicked == "Remove 100% cloud"){
for(int i = 0; i < 100; i++){
decreaseCloud();
}
}
//Timer
else if(uiClicked == "Add 1 hour"){
for(int i = 0; i < 60; i++){
moveSunForward();
listHandler.lists.get(3).modifyListHeader("Time: (" + sun.currentTime() + ")" + "(" + autoString() +")");
}
}
else if(uiClicked == "Go back 1 hour"){
for(int i = 0; i < 60; i++){
moveSunBackward();
listHandler.lists.get(3).modifyListHeader("Time: (" + sun.currentTime() + ")" + "(" + autoString() +")");
}
}
//Stars
else if(uiClicked == "Add 10 stars"){
for(int i = 0; i < 10; i++){
increaseStars();
listHandler.lists.get(4).modifyListHeader("Star: (" + sky.starDensity() + ")");
}
}
else if(uiClicked == "Remove 10 stars"){
for(int i = 0; i < 10; i++){
decreaseStars();
listHandler.lists.get(4).modifyListHeader("Star: (" + sky.starDensity() + ")");
}
}
//Volume
if(uiClicked == "Increase limit"){
entityHandler.setVolumeLimit(0.01);
String a = nf(entityHandler.volumeLimit, 1, 2);
listHandler.lists.get(5).modifyListHeader("Volume limit: (" + a + ")");
}
else if(uiClicked == "Reduce limit"){
entityHandler.setVolumeLimit(-0.01);
String a = nf(entityHandler.volumeLimit, 1, 2);
listHandler.lists.get(5).modifyListHeader("Volume limit: (" + a + ")");
}
else if(uiClicked == "Reset limit"){
entityHandler.setVolumeLimit(-entityHandler.volumeLimit + 0.07);
String a = nf(entityHandler.volumeLimit, 1, 2);
listHandler.lists.get(5).modifyListHeader("Volume limit: (" + a + ")");
}
}
//Weather Stuff
void setRain() {
drawRain = !drawRain;
}
void setClouds() {
drawCloud = !drawCloud;
}
void setThunder() {
drawThunder = !drawThunder;
}
void setInstructions() {
drawInstructions = !drawInstructions;
}
void setSun() {
drawSun = !drawSun;
}
void setMoon() {
drawMoon = !drawMoon;
}
void setGround() {
drawGround = !drawGround;
}
void increaseRain() {
rain.increaseRainPrecip();
}
void decreaseRain() {
rain.decreaseRainPrecip();
}
void increaseCloud(){
cloud.increaseCloudDen();
}
void decreaseCloud(){
cloud.decreaseCloudDen();
}
void moveSunForward() {
sun.sunForward();
}
void moveSunBackward() {
sun.sunBack();
}
void autoSun() {
sun.setAutoSun();
}
void increaseStars(){
sky.instantiateStars();
}
void decreaseStars(){
sky.destroyStar();
}
void setStars(){
drawStars = !drawStars;
}
//Add food
void addFood(){
entityHandler.addEntity();
}
String autoString(){
if(sun.isAutoSun()){
return "AUTO";
}
else{
return "MANUAL";
}
}
}