-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
173 lines (131 loc) · 3.69 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>Season Machine</title>
<!-- Load the Processing.js library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/processing.js/1.6.0/processing.min.js"></script>
</head>
<body>
<script type="application/processing">
void setup(){ size(1200, 600); }
//This code belongs to Mathias Zarate Diaz, AKA LumaControl. Feel free to use some of it, but DO NOT COPY AS A WHOLE PROGRAM.
// Time of day variables
var timeOfDay = ["day","night"];
var timeOfDayPos = 0;
var date = 0;
//Default background colour (nighttime)
var backgroundColour = [10, 10, 100];
// Season variables
var seasons = ["winter","spring","summer","autumn"];
var seasonCyclePos = 0;
// Sun position variables
var sunX = -70;
var sunY = 0;
// Moon position variables
var moonX = -70;
var moonY = 0;
// house variables
var houseX = 289;
var houseY = 253;
var houseSize = 100;
var windowColourNight = [10,10,100];
var windowColourDay = [255, 208, 0];
// Updates location of sun whenever function is called.
var sunUpdate = function() {
sunX += 3;
sunY = 0.08*(sunX-200) * 0.08*(sunX-200) + 10;
fill (255, 242, 0);
ellipse(sunX,sunY,100,100);
};
var moonUpdate = function() {
if (timeOfDayPos === 1) {
moonX += 3;
moonY = 0.08*(moonX-200) * 0.08*(moonX-200) + 10;
fill (150, 150, 150);
ellipse(moonX,moonY,100,100);
fill (117, 113, 117);
ellipse(moonX-20,moonY-30,22,19);
ellipse(moonX-20,moonY+20,29,33);
ellipse(moonX+20,moonY-5,25,36);
}
else {
moonX = -70;
}
};
// Updates background colour dependent on sun state.
var backgroundUpdate = function() {
background(backgroundColour[0],backgroundColour[1],backgroundColour[2]);
if (sunX > -50 && sunX < 200) {
backgroundColour[1] = backgroundColour[1] + 2;
backgroundColour[2] = backgroundColour[2] + 2;
}
if (sunX > 300 && sunX < 550) {
backgroundColour[1] = backgroundColour[1] - 2;
backgroundColour[2] = backgroundColour[2] - 2;
}
};
//Updates the timeOfDayPos integer dependent on the sun state.
var timeOfDayUpdate = function() {
if (sunX >= 470) {timeOfDayPos = 1;}
if (sunX >= 1010) {timeOfDayPos = 0;sunX = -70; date++;}
return timeOfDay[timeOfDayPos];
};
var currentSeason = function() {
//TODO: fix this horrible statement. Doesn't work like it should :)
switch(true) {
case date >= 0 <= 2:
fill(255, 255, 255);
text("spring",200,200);
break;
case date >= 3:
text("summer",200,200);
break;
case date >= 6:
text("autumn",200,200);
break;
case date >= 9:
text("winter",200,200);
break;
case date >= 12:
date = 0;
break;
}
};
frameRate(60);
noStroke();
var drawHouse = function() {
fill(163, 155, 142);
//House body
rect(houseX,houseY,houseSize,houseSize-20);
fill(153, 43, 43);
triangle(houseX-10,houseY,houseX+50,houseY+-62,houseX+110,houseY);
//Interior lights logic
if (timeOfDayPos === 1) {
fill(windowColourDay[0],windowColourDay[1],windowColourDay[2]);
}
if (timeOfDayPos === 0) {
fill(windowColourNight[0],windowColourNight[1],windowColourNight[2]);
}
//windows
rect(houseX+10,houseY+10,houseSize/4,houseSize/4);
rect(houseX+60,houseY+10,houseSize/4,houseSize/4);
};
//Main function
draw = function() {
backgroundUpdate();
sunUpdate();
moonUpdate();
fill(232, 198, 5);
currentSeason();
fill(36, 150, 70);
rect(0,333,408,69);
text(date,51,30);
text(timeOfDay[timeOfDayPos],23,30);
timeOfDayUpdate();
drawHouse();
};
};
</script>
<canvas> </canvas>
</body>
</html>