-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
377 lines (330 loc) · 19.6 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
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="theme-color" content="#778899">
<link rel="manifest" href="manifest.json" />
<link rel="apple-touch-icon" href="images/icon.png"/>
<link rel="icon" type="image/png" href="images/icon.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)" href="images/12.9__iPad_Pro_landscape.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 834px) and (device-height: 1194px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)" href="images/11__iPad_Pro__10.5__iPad_Pro_landscape.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 834px) and (device-height: 1112px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)" href="images/10.5__iPad_Air_landscape.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 810px) and (device-height: 1080px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)" href="images/10.2__iPad_landscape.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 768px) and (device-height: 1024px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)" href="images/9.7__iPad_Pro__7.9__iPad_mini__9.7__iPad_Air__9.7__iPad_landscape.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 428px) and (device-height: 926px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)" href="images/iPhone_13_Pro_Max__iPhone_12_Pro_Max_landscape.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 390px) and (device-height: 844px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)" href="images/iPhone_13_Pro__iPhone_13__iPhone_12_Pro__iPhone_12_landscape.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)" href="images/iPhone_13_mini__iPhone_12_mini__iPhone_11_Pro__iPhone_XS__iPhone_X_landscape.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)" href="images/iPhone_11_Pro_Max__iPhone_XS_Max_landscape.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)" href="images/iPhone_11__iPhone_XR_landscape.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 414px) and (device-height: 736px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)" href="images/iPhone_8_Plus__iPhone_7_Plus__iPhone_6s_Plus__iPhone_6_Plus_landscape.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)" href="images/iPhone_8__iPhone_7__iPhone_6s__iPhone_6__4.7__iPhone_SE_landscape.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)" href="images/4__iPhone_SE__iPod_touch_5th_generation_and_later_landscape.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)" href="images/12.9__iPad_Pro_portrait.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 834px) and (device-height: 1194px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)" href="images/11__iPad_Pro__10.5__iPad_Pro_portrait.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 834px) and (device-height: 1112px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)" href="images/10.5__iPad_Air_portrait.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 810px) and (device-height: 1080px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)" href="images/10.2__iPad_portrait.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 768px) and (device-height: 1024px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)" href="images/9.7__iPad_Pro__7.9__iPad_mini__9.7__iPad_Air__9.7__iPad_portrait.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 428px) and (device-height: 926px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)" href="images/iPhone_13_Pro_Max__iPhone_12_Pro_Max_portrait.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 390px) and (device-height: 844px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)" href="images/iPhone_13_Pro__iPhone_13__iPhone_12_Pro__iPhone_12_portrait.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)" href="images/iPhone_13_mini__iPhone_12_mini__iPhone_11_Pro__iPhone_XS__iPhone_X_portrait.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)" href="images/iPhone_11_Pro_Max__iPhone_XS_Max_portrait.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)" href="images/iPhone_11__iPhone_XR_portrait.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 414px) and (device-height: 736px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)" href="images/iPhone_8_Plus__iPhone_7_Plus__iPhone_6s_Plus__iPhone_6_Plus_portrait.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)" href="images/iPhone_8__iPhone_7__iPhone_6s__iPhone_6__4.7__iPhone_SE_portrait.png">
<link rel="apple-touch-startup-image" media="screen and (device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)" href="images/4__iPhone_SE__iPod_touch_5th_generation_and_later_portrait.png">
<title>helios</title>
<script type="module" src="https://cdn.jsdelivr.net/npm/@pwabuilder/pwaupdate"></script>
<script type="text/javascript" src="scripts\jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="scripts\jquery-ui.min.js"></script>
<script type="text/javascript" src="scripts\paper-full.min.js"></script>
<script type="text/javascript" src="scripts\suncalc.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#canvas").fadeIn(1500, "easeInOutQuart");
$(window).resize(function(){location.reload();});
});
</script>
<script type="text/paperscript" canvas="canvas">
//Define parameters
var sunRadius = 10;
var xBuffer = 0;
var xSize = ((window.innerWidth > 0) ? window.innerWidth : screen.width) - (2 * xBuffer);
var ySize = 200;
var yBuffer = Math.max(((window.innerHeight - ySize) / 2), 1 + sunRadius);
var lineColour = 'white';
//Initialise objects
var location = new Location();
var sunTimes = new SunTimes(location);
var altimeter = new Altimeter(sunTimes, ySize);
var heliosPath = new HeliosPath(altimeter, sunTimes.DegreeMidday, lineColour, xSize, yBuffer);
var horizon = new Horizon(altimeter, sunTimes.Sunrise, lineColour, xSize, yBuffer);
var helios = new Helios(altimeter, horizon.HorizonYCoordinate, lineColour, sunRadius, xSize, yBuffer);
//Events
function onFrame(event) {
location.Update(locationCallback);
sunTimes.Update(location);
heliosPath.Update(sunTimes.DegreeMidday);
horizon.Update(sunTimes.Sunrise);
helios.Update(horizon.HorizonYCoordinate);
}
function locationCallback() {
sunTimes.Update(location);
heliosPath.Update(sunTimes.DegreeMidday);
horizon.Update(sunTimes.Sunrise);
}
//Objects
function Location() {
var latitude = localStorage.latitude ? localStorage.latitude : 0;
var longitude = localStorage.longitude ? localStorage.longitude : 0;
this.__defineGetter__("Latitude", function(){ return latitude; });
this.__defineGetter__("Longitude", function(){ return longitude; });
var secondsInDay = 60 * 60 * 24;
var previousRequest = new Date(1970, 1, 1, 0, 0, 0, 0);
this.Update = function(callback) {
var date = new Date();
//Update location once a day or if we have no data try each hour
var requiresUpdate = (!localStorage.locationAsOf || date - localStorage.locationAsOf >= 1000 * secondsInDay) && date - previousRequest >= 1000 * 60 * 60;
previousRequest = date;
if (requiresUpdate){
console.log('Requesting location...');
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
function(location) {
latitude = location.coords.latitude;
longitude = location.coords.longitude;
localStorage.latitude = latitude;
localStorage.longitude = longitude;
localStorage.locationAsOf = new Date();
callback();
console.log('Location retrieved (latitude: ' + latitude + ', longitude: ' + longitude + ')');
},
function (error) {
console.log('Unable to retrieve location: ' + error.message);
},
{
enableHighAccuracy: false,
timeout: 15000,
maximumAge: 0
} );
} else {
console.log('Unable to retrieve location: Unavailable');
}
}
}
}
function SunTimes(location) {
var sunrise = new Date(1970, 1, 1, 0, 0, 0, 0);
var sunset = new Date(1970, 1, 1, 0, 0, 0, 0);
var degreeMidday = new Date(1970, 1, 1, 0, 0, 0, 0);
this.__defineGetter__("Sunrise", function(){ return sunrise; });
this.__defineGetter__("Sunset", function(){ return sunset; });
this.__defineGetter__("DegreeMidday", function(){ return degreeMidday; });
this.Update = update;
var secondsInDay = 60 * 60 * 24;
var previousRequest = new Date(1970, 1, 1, 0, 0, 0, 0);
var latitude = location.Latitude;
var longitude = location.Longitude;
update(location);
function update(location) {
var date = (new Date()).setHours(0,0,0,0);
if (date > previousRequest || latitude != location.Latitude || longitude != location.Longitude) {
var times = SunCalc.getTimes(new Date(), location.Latitude, location.Longitude);
sunrise = times.sunrise != 'Invalid Date' ? times.sunrise : new Date(1970, 1, 1, 0, 0, 0, 0);
sunset = times.sunset != 'Invalid Date' ? times.sunset : new Date(1970, 1, 1, 23, 59, 59, 999);
var midday = (secondsSinceStartOfDay(sunrise) + secondsSinceStartOfDay(sunset)) / 2;
degreeMidday = 360 * midday / secondsInDay;
latitude = location.Latitude;
longitude = location.Longitude;
previousRequest = date;
}
}
function secondsSinceStartOfDay(date) {
return date.getSeconds() + (60 * date.getMinutes()) + (60 * 60 * date.getHours());
}
}
function Altimeter(sunTimes, ySize) {
this.FractionalTime = fractionalTime;
this.Altitude = altitude;
function fractionalTime(date) {
var secondsInDay = 60 * 60 * 24;
var seconds = secondsSinceStartOfDay(date);
return seconds / secondsInDay;
}
function secondsSinceStartOfDay(date) {
return date.getSeconds() + (60 * date.getMinutes()) + (60 * 60 * date.getHours());
}
function altitude(fractionalTime) {
var degreeTime = 360 * fractionalTime;
var fractionalAltitude = (1 + Math.cos((degreeTime + 180 - sunTimes.DegreeMidday) * Math.PI / 180)) / 2;
return fractionalAltitude * ySize;
}
}
function HeliosPath(altimeter, degreeMidday, colour, xSize, yBuffer) {
this.Update = update;
var pathPoints = 360;
var heliosPath = new Path();
heliosPath.strokeColor = colour;
var previousRequest = new Date(1970, 1, 1, 0, 0, 0, 0);
update(degreeMidday);
function update(newDegreeMidday) {
var date = (new Date()).setHours(0,0,0,0);
if (date > previousRequest || degreeMidday != newDegreeMidday) {
heliosPath.removeSegments();
for (var i = 0; i <= pathPoints; i++) {
var point = new Point(xBuffer + ( xSize * i / pathPoints), yBuffer + altimeter.Altitude(i / pathPoints));
heliosPath.add(point);
}
heliosPath.smooth();
heliosPath.simplify();
degreeMidday = newDegreeMidday;
previousRequest = date;
}
}
}
function Horizon(altimeter, sunrise, colour, xSize, yBuffer) {
var horizonYCoordinate = 0;
this.__defineGetter__("HorizonYCoordinate", function(){ return horizonYCoordinate; });
this.Update = update;
var horizon = new Path.Line();
horizon.strokeColor = colour;
var previousRequest = new Date(1970, 1, 1, 0, 0, 0, 0);
update(sunrise);
function update(newSunrise) {
var date = (new Date()).setHours(0,0,0,0);
if (date > previousRequest || sunrise != newSunrise) {
horizon.removeSegments();
var horizonAltitude = altimeter.Altitude(altimeter.FractionalTime(newSunrise));
horizonYCoordinate = yBuffer + horizonAltitude;
var from = new Point(xBuffer, horizonYCoordinate);
var to = new Point(xBuffer + xSize, horizonYCoordinate);
horizon.add(from);
horizon.add(to);
sunrise = newSunrise;
previousRequest = date;
}
}
}
function Helios(altimeter, horizon, colour, radius, xSize, yBuffer) {
this.Update = update;
var glow = 25;
var framesPerSecond = 1;
var horizonYCoordinate = 0;
var previousRequest = new Date(1970, 1, 1, 0, 0, 0, 0);
var modifiedAnimationDuration = null;
var detailsText = $('#cycleTime');
detailsText.css('color', lineColour);
//The glow around helios
var heliosGlow = new Path.Circle(-((glow * 10) + 1), 0, glow);
heliosGlow.fillColor = {
gradient: {
stops: [['yellow', radius/glow], [new RgbColor(1, 1, 1, 0.0), 1.0]],
radial: true
},
origin: heliosGlow.position,
destination: heliosGlow.bounds.rightCenter
};
//Our main helios circle
var heliosCircle = new Path.Circle(-(glow + 1), 0, radius);
heliosCircle.fillColor = lineColour;
//The outline for use when helios is below the horizon
var heliosOutline = new Path.Circle(-(glow + 1), 0, radius);
heliosOutline.strokeColor = 'white';
//Objects for use when helios is exiting the screen
var wrapGlow = heliosGlow.clone();
var wrapCircle = heliosCircle.clone();
var wrapOutline = heliosOutline.clone();
update(horizon);
function update(newHorizon, forceUpdate) {
var date = new Date();
if (date - previousRequest >= 1000 / framesPerSecond || forceUpdate) {
var timeFraction = altimeter.FractionalTime(date);
//Run the animation faster
if (modifiedAnimationDuration) {
timeFraction = (date.getMilliseconds() + ((date.getSeconds() % modifiedAnimationDuration) * 1000)) / (1000 * modifiedAnimationDuration);
}
heliosCircle.position.x = heliosGlow.position.x = heliosOutline.position.x = xBuffer + (xSize * timeFraction);
heliosCircle.position.y = heliosGlow.position.y = heliosOutline.position.y = yBuffer + altimeter.Altitude(timeFraction);
if (newHorizon != horizonYCoordinate || !horizonYCoordinate) {
horizonYCoordinate = newHorizon;
clip(horizonYCoordinate);
}
sunset();
wrapHelios();
previousRequest = date;
}
}
function clip(horizonYCoordinate) {
var from = new Point(0, 0);
var to = new Point(xSize, horizonYCoordinate);
var aboveHorizon = new Path.Rectangle(from, to);
var group = new Group(aboveHorizon, heliosGlow, heliosCircle, wrapGlow, wrapCircle);
group.clipped = true;
}
function sunset() {
//How close to the horizon do we want the sunset to kick in
var sunsetProximity = 2 * radius;
//The green level is determined by how far we are through the sunset
var green = 1- ((heliosCircle.position.y + sunsetProximity - horizonYCoordinate) / sunsetProximity);
//Clip to 0.4 -> 1
green = Math.max(Math.min(green,1),0);
green = 0.6 * (((1/0.6)-1) + green);
//Add twilight once the sun is below the horizon
var twilight = (heliosCircle.position.y - horizonYCoordinate) / (2 * radius);
twilight = Math.max(Math.min(twilight,1),0);
//Set
heliosGlow.fillColor.gradient.stops[0].color = new Color(1 - twilight, Math.max(green - twilight, 0), 0.2 * twilight);
//Size
var growFactor = Math.abs((heliosCircle.position.y - (horizonYCoordinate + radius)) / (3 * radius));
growFactor = 1 - Math.min(growFactor,1);
var relativeScale = (1 + (1 * growFactor)) * (glow / (heliosGlow.bounds.width / 2));
heliosGlow.scale(relativeScale);
wrapGlow.scale(relativeScale);
}
//Use second object to create wrapping effect
function wrapHelios() {
if (heliosCircle.position.x + (heliosGlow.bounds.width / 2) > xBuffer + xSize) {
wrapCircle.position.x = wrapOutline.position.x = wrapGlow.position.x = heliosCircle.position.x - (xBuffer + xSize);
wrapCircle.position.y = wrapOutline.position.y = wrapGlow.position.y = heliosCircle.position.y;
wrapGlow.fillColor.gradient.stops[0].color = heliosGlow.fillColor.gradient.stops[0].color;
} else if (heliosCircle.position.x < (heliosGlow.bounds.width / 2)) {
wrapCircle.position.x = wrapOutline.position.x = wrapGlow.position.x = heliosCircle.position.x + (xBuffer + xSize);
wrapCircle.position.y = wrapOutline.position.y = wrapGlow.position.y = heliosCircle.position.y;
wrapGlow.fillColor.gradient.stops[0].color = heliosGlow.fillColor.gradient.stops[0].color;
} else {
wrapCircle.position.x = wrapOutline.position.x = wrapGlow.position.x = -((glow * 10) + 1);
}
}
heliosCircle.onClick = heliosGlow.onClick = wrapCircle.onClick = wrapGlow.onClick = function(event) {
//Increment the animation cycle time as follows (null means default 1 day behaviour)
if (!modifiedAnimationDuration) {
modifiedAnimationDuration = 10;
} else if (modifiedAnimationDuration == 10) {
modifiedAnimationDuration = 30;
} else if (modifiedAnimationDuration == 30) {
modifiedAnimationDuration = 60;
} else if (modifiedAnimationDuration == 60) {
modifiedAnimationDuration = null;
}
//If we're running the animation faster then set the frames per second to 60
framesPerSecond = modifiedAnimationDuration ? 60 : 1;
//Show some details
if (modifiedAnimationDuration) {
detailsText.show();
detailsText.html(modifiedAnimationDuration + 's solar cycle');
detailsText.css('top', (yBuffer + altimeter.Altitude(1) + radius) + 'px');
} else {
detailsText.hide();
}
update(horizonYCoordinate, true);
}
}
</script>
</head>
<body style="margin: 0; background-color: lightslategray;">
<canvas id="canvas" resize style="display: none;"></canvas>
<h6 id="cycleTime" style="font-weight: normal; position: absolute; right: 1px; margin: 0; font-family: verdana,helvetica,arial,sans-serif;"></h6>
<pwa-update swpath="https://filmstarr.github.io/helios/pwabuilder-sw.js"></pwa-update>
</body>
</html>