-
Notifications
You must be signed in to change notification settings - Fork 1
/
scripts.js
67 lines (60 loc) · 3.02 KB
/
scripts.js
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
window.addEventListener('load', () => {
var button = document.getElementById("start");
button.onclick = function() {
var d = new Date();
console.log(d.getSeconds());
console.log(d.getHours());
console.log(d.getMinutes());
console.log(d.getMilliseconds());
totalSeconds = (d.getSeconds() + ((d.getHours() * 60) * 60) + (d.getMinutes() * 60) + (d.getMilliseconds() / 1000));
console.log(totalSeconds);
document.getElementById('skyGradient').children[0].children[0].setAttribute("begin", '-' + totalSeconds + 's');
document.getElementById('skyGradient').children[0].children[1].setAttribute("begin", '-' + totalSeconds + 's');
document.getElementById('skyGradient').children[1].children[0].setAttribute("begin", '-' + totalSeconds + 's');
document.getElementById('skyGradient').children[0].children[0].setAttribute("dur", '86400s');
document.getElementById('skyGradient').children[0].children[1].setAttribute("dur", '86400s');
document.getElementById('skyGradient').children[1].children[0].setAttribute("dur", '86400s');
document.getElementById("skyGradient").innerHTML += ""; //reload the svgs
document.getElementsByClassName('sun')[0].style.animationDuration = "86400s";
document.getElementsByClassName('moon')[0].style.animationDuration = "86400s";
document.getElementsByClassName('sun')[0].style.animationDelay = '-' + totalSeconds + 's';
document.getElementsByClassName('moon')[0].style.animationDelay = '-' + totalSeconds + 's';
};
for(var i = 0; i < 25; i++) {
var cloudSpeed = Math.floor(Math.random() * 30) + 1;
console.log(cloudSpeed);
var div = document.createElement("img");
div.style.animationDuration = (15 * (1 + (cloudSpeed / 10))) + "s";
div.style.animationDelay = "-" + (((Math.floor(Math.random() * 100) + 1) / 100) * (15 * (1 + (cloudSpeed / 10))))+ "s";
div.style.width = (30 * (cloudSpeed / 60)) + "%";
// div.style.height = "auto";
// div.style.transform = "scale(" + (Math.floor(Math.random() * 100) + 0) + ")";
div.style.opacity = (cloudSpeed / 20);
div.className = "cloud";
div.src = "media/clouds/cloud0" + (Math.floor(Math.random() * 5) + 1) + ".png";
div.style.top = (Math.floor(Math.random() * 70) + 1) + "vh";
document.getElementById("clouds").appendChild(div);
}
const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d");
const video = document.querySelector("video");
video.addEventListener('play', () => {
function step() {
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
requestAnimationFrame(step);
}
requestAnimationFrame(step);
});
//Clock functionality
let clockUpdate = () => {
const time = document.getElementById("time");
let d = new Date();
let currentHour = d.getHours();
let hourDisplay = currentHour % 12 == 0 ? 12 : currentHour % 12;
let minuteDisplay = String(d.getMinutes()).padStart(2, "0");
let milliseconds = d.getMilliseconds();
time.textContent = milliseconds > 500 ? `${hourDisplay} ${minuteDisplay}` : `${hourDisplay}:${minuteDisplay}`;
}
clockUpdate();
setInterval(clockUpdate, 500);
});