-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweather.html
179 lines (179 loc) · 8.37 KB
/
weather.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
174
175
176
177
178
179
<!DOCTYPE html>
<html>
<head>
<title>yo weather</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<style>
body {
max-width: 1000px;
margin: 20px auto;
padding: 0 20px;
font-family: sans-serif;
}
input, button, select, textarea {
font: inherit;
}
p {
white-space: pre-wrap;
}
span.red {
color: red;
}
</style>
</head>
<body>
<h1>Toast Countries Weather</h1>
<button id="hor" title="view weather for day before"><<<</button>
<button id="mor" title="view weather for day after" disabled>>>></button>
<p id="bleh"></p>
<script>
var regions={
"Arctic":{
temperature:{veryCold:50,cold:40,somewhatCold:10,roomTemperature:0,warm:0,hot:0,veryHot:0},
wind:{noWind:20,breeze:60,windy:20,veryWindy:0,extremelyWindy:0},
clouds:{noClouds:20,someClouds:20,cloudyDay:10,lightRain:30,heavyRain:15,storm:5,monsoon:0}
},"North United States":{
temperature:{veryCold:0,cold:0,somewhatCold:0,roomTemperature:0,warm:0,hot:0,veryHot:0},
wind:{noWind:0,breeze:0,windy:0,veryWindy:0,extremelyWindy:0},
clouds:{noClouds:0,someClouds:0,cloudyDay:0,lightRain:0,heavyRain:0,storm:0,monsoon:0}
},"Middle United States":{
temperature:{veryCold:0,cold:0,somewhatCold:0,roomTemperature:0,warm:0,hot:0,veryHot:0},
wind:{noWind:0,breeze:0,windy:0,veryWindy:0,extremelyWindy:0},
clouds:{noClouds:0,someClouds:0,cloudyDay:0,lightRain:0,heavyRain:0,storm:0,monsoon:0}
},"South United States":{
temperature:{veryCold:0,cold:0,somewhatCold:0,roomTemperature:0,warm:55,hot:25,veryHot:20},
wind:{noWind:85,breeze:10,windy:5,veryWindy:0,extremelyWindy:0},
clouds:{noClouds:55,someClouds:25,cloudyDay:15,lightRain:1,heavyRain:2,storm:2,monsoon:0}
},"Central America":{
temperature:{veryCold:0,cold:0,somewhatCold:10,roomTemperature:20,warm:35,hot:25,veryHot:10},
wind:{noWind:40,breeze:40,windy:15,veryWindy:4,extremelyWindy:1},
clouds:{noClouds:50,someClouds:10,cloudyDay:0,lightRain:20,heavyRain:15,storm:5,monsoon:0}
},"Southern America":{
temperature:{veryCold:0,cold:0,somewhatCold:0,roomTemperature:0,warm:0,hot:0,veryHot:0},
wind:{noWind:0,breeze:0,windy:0,veryWindy:0,extremelyWindy:0},
clouds:{noClouds:0,someClouds:0,cloudyDay:0,lightRain:0,heavyRain:0,storm:0,monsoon:0}
},"North Asia":{
temperature:{veryCold:10,cold:40,somewhatCold:30,roomTemperature:15,warm:5,hot:0,veryHot:0},
wind:{noWind:30,breeze:40,windy:20,veryWindy:10,extremelyWindy:0},
clouds:{noClouds:10,someClouds:20,cloudyDay:50,lightRain:15,heavyRain:5,storm:0,monsoon:0}
},"Central Asia":{
temperature:{veryCold:3,cold:17,somewhatCold:16,roomTemperature:24,warm:17,hot:18,veryHot:5},
wind:{noWind:8,breeze:24,windy:39,veryWindy:20,extremelyWindy:9},
clouds:{noClouds:63,someClouds:18,cloudyDay:7,lightRain:5,heavyRain:3,storm:4,monsoon:0}
},"East Asia":{
temperature:{veryCold:0,cold:0,somewhatCold:5,roomTemperature:20,warm:30,hot:35,veryHot:10},
wind:{noWind:10,breeze:20,windy:20,veryWindy:35,extremelyWindy:15},
clouds:{noClouds:5,someClouds:20,cloudyDay:25,lightRain:20,heavyRain:20,storm:10,monsoon:0}
},"Southeast Asia":{
temperature:{veryCold:0,cold:0,somewhatCold:0,roomTemperature:0,warm:0,hot:0,veryHot:0},
wind:{noWind:0,breeze:0,windy:0,veryWindy:0,extremelyWindy:0},
clouds:{noClouds:0,someClouds:0,cloudyDay:0,lightRain:0,heavyRain:0,storm:0,monsoon:0}
},"Australia":{
temperature:{veryCold:0,cold:0,somewhatCold:0,roomTemperature:0,warm:0,hot:0,veryHot:0},
wind:{noWind:0,breeze:0,windy:0,veryWindy:0,extremelyWindy:0},
clouds:{noClouds:0,someClouds:0,cloudyDay:0,lightRain:0,heavyRain:0,storm:0,monsoon:0}
},"Middle East":{
temperature:{veryCold:1,cold:2,somewhatCold:3,roomTemperature:40,warm:35,hot:11,veryHot:8},
wind:{noWind:35,breeze:30,windy:20,veryWindy:10,extremelyWindy:5},
clouds:{noClouds:60,someClouds:20,cloudyDay:10,lightRain:7,heavyRain:2,storm:1,monsoon:0}
},"South Asia":{
temperature:{veryCold:1,cold:2,somewhatCold:5,roomTemperature:45,warm:35,hot:0,veryHot:12},
wind:{noWind:25,breeze:40,windy:25,veryWindy:5,extremelyWindy:5},
clouds:{noClouds:75,someClouds:10,cloudyDay:5,lightRain:5,heavyRain:0,storm:0,monsoon:5}
},"Northern Europe":{
temperature:{veryCold:10,cold:30,somewhatCold:20,roomTemperature:20,warm:10,hot:5,veryHot:5},
wind:{noWind:40,breeze:20,windy:20,veryWindy:10,extremelyWindy:10},
clouds:{noClouds:30,someClouds:30,cloudyDay:10,lightRain:10,heavyRain:10,storm:10,monsoon:0}
},"Southern Europe":{
temperature:{veryCold:10,cold:10,somewhatCold:20,roomTemperature:30,warm:20,hot:5,veryHot:5},
wind:{noWind:40,breeze:20,windy:20,veryWindy:10,extremelyWindy:10},
clouds:{noClouds:30,someClouds:30,cloudyDay:10,lightRain:10,heavyRain:10,storm:10,monsoon:0}
},"Northern Africa":{
temperature:{veryCold:0,cold:0,somewhatCold:0,roomTemperature:0,warm:10,hot:40,veryHot:50},
wind:{noWind:95,breeze:5,windy:0,veryWindy:0,extremelyWindy:0},
clouds:{noClouds:90,someClouds:10,cloudyDay:0,lightRain:0,heavyRain:0,storm:0,monsoon:0}
},"Southern Africa":{
temperature:{veryCold:0,cold:15,somewhatCold:20,roomTemperature:25,warm:20,hot:20,veryHot:0},
wind:{noWind:20,breeze:50,windy:30,veryWindy:0,extremelyWindy:0},
clouds:{noClouds:60,someClouds:20,cloudyDay:10,lightRain:10,heavyRain:0,storm:0,monsoon:0}
},"Antarctica":{
temperature:{veryCold:50,cold:40,somewhatCold:10,roomTemperature:0,warm:0,hot:0,veryHot:0},
wind:{noWind:20,breeze:60,windy:20,veryWindy:0,extremelyWindy:0},
clouds:{noClouds:50,someClouds:30,cloudyDay:10,lightRain:5,heavyRain:3,storm:2,monsoon:0}
}
},
english={
veryCold:"very cold",
cold:"cold",
somewhatCold:'somewhat cold',
roomTemperature:'room temperature',
warm:'warm',hot:'hot',veryHot:'very hot',
noWind:'no wind',breeze:'breeze',windy:'windy',veryWindy:'very windy',extremelyWindy:'extremely windy',
noClouds:'no clouds',someClouds:'some clouds',cloudyDay:'cloudy day',lightRain:'light rain/snow',heavyRain:'heavy rain/snow',
storm:'storm',monsoon:'monsoon'
},
months='January February March April May June July August September October November December'.split(' ');
class Random {
constructor(seed) {
this._seed=seed%2147483647;
if (this._seed<=0) this._seed+=2147483646;
}
next() {
return this._seed=this._seed*16807%2147483647;
}
nextFloat() {
return (this.next()-1)/2147483646;
}
}
function generateWeather(offset) {
var day=new Date();
day=new Date(day.getFullYear(),day.getMonth(),day.getDate()+offset)
var random=new Random(day.getTime()),
output=`<p>Weather for ${months[day.getMonth()]} ${day.getDate()}, ${day.getFullYear()}</p>`,
t;
for (var region in regions) {
output+='<h2>'+region+'</h2><p>';
t=randomValue(random,regions[region].temperature);
if (typeof t==='number') output+='<span class="red">sum of percent chances for TEMPERATURE is '+(t>0?t+'% too high':-t+'% too low')+'</span>; ';
else output+='temperature: <strong>'+english[t]+'</strong>; ';
t=randomValue(random,regions[region].wind);
if (typeof t==='number') output+='<span class="red">sum of percent chances for WIND is '+(t>0?t+'% too high':-t+'% too low')+'</span>; ';
else output+='wind: <strong>'+english[t]+'</strong>; ';
t=randomValue(random,regions[region].clouds);
if (typeof t==='number') output+='<span class="red">sum of percent chances for CLOUDS is '+(t>0?t+'% too high':-t+'% too low')+'</span>';
else output+='clouds: <strong>'+english[t]+'</strong>';
output+='</p>';
}
return output;
}
function randomValue(random,obj) {
var sum=0,stops=[],corres=[];
for (var a in obj) {
sum+=obj[a];
stops.push(sum);
corres.push(a);
}
var num=Math.floor(random.nextFloat()*100);
if (sum!==100) return sum-100;
for (var i=0;i<stops.length;i++) {
if (num<stops[i]) return corres[i];
}
throw new Error("wat");
}
var boop=document.querySelector('#bleh'),
offset=0;
boop.innerHTML=generateWeather(0);
document.querySelector('#hor').onclick=e=>{
offset--;
if (offset<0) document.querySelector('#mor').disabled=false;
boop.innerHTML=generateWeather(offset);
};
document.querySelector('#mor').onclick=e=>{
if (offset<0) offset++;
if (offset>=0) document.querySelector('#mor').disabled=true;
boop.innerHTML=generateWeather(offset);
};
</script>
</body>
</html>