~acdw/old-blog-content

old-blog-content/static/start.html -rw-r--r-- 1.1 KiB
fe27705eCase Duckworth Add poem 11 months ago
                                                                                
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
<!DOCTYPE html>
<title>start here</title>
<meta charset=utf-8>

<style>
body,html,main,#canvas {
	margin: 0;
	padding: 0;
}
html, body { width: 100%; height: 100%; }
canvas { display: block; }
</style>

<main>
	<canvas id=canvas width=400 height=600></canvas>
</main>

<script>
	const canvas = document.getElementById('canvas');
	const ctx = canvas.getContext('2d');
	function resizeCanvas() {
		canvas.width = window.innerWidth;
		canvas.height = window.innerHeight;
		update();
	}
	function update() {
		const now = new Date();
		const hours = now.getMinutes();
		const mins = now.getSeconds();

		console.log(hours, mins);

		if (mins == 0) {
			ctx.fillStyle = 'white';
			ctx.fillRect(0, 0, canvas.width, canvas.height);
		}

		ctx.fillStyle = 'green';
		ctx.fillRect(
			hours * canvas.width / 60 * Math.sin(mins),
			mins * canvas.height / 60,
			canvas.width, 1);
		ctx.fillStyle = 'purple';
		ctx.fillRect(
			mins * canvas.width / 60,
			hours * canvas.height / 60 * Math.cos(mins),
			1, canvas.height);
	}
	var updateID = window.setInterval(update, 1000);
	window.addEventListener('resize', resizeCanvas, false);
	resizeCanvas();
</script>