|
1 | 1 | ---
|
2 |
| -import Layout from '../layouts/Layout.astro'; |
| 2 | +import Layout from '@layouts/Layout.astro'; |
3 | 3 | ---
|
4 | 4 |
|
5 | 5 | <Layout title="404 - Sam de Kanter" description="Page not found">
|
@@ -58,80 +58,80 @@ import Layout from '../layouts/Layout.astro';
|
58 | 58 | </Layout>
|
59 | 59 |
|
60 | 60 | <script lang="ts">
|
61 |
| -const canvas = document.querySelector('canvas'); |
| 61 | + const canvas = document.querySelector('canvas'); |
62 | 62 |
|
63 |
| -let ctx; |
| 63 | + let ctx; |
64 | 64 |
|
65 |
| -function random(a, b) { |
66 |
| - if (b === undefined) return Math.random() * a; |
67 |
| - return a + Math.random() * (b - a); |
68 |
| -} |
| 65 | + function random(a, b) { |
| 66 | + if (b === undefined) return Math.random() * a; |
| 67 | + return a + Math.random() * (b - a); |
| 68 | + } |
69 | 69 |
|
70 |
| -function setCanvasSize() { |
71 |
| - if (ctx) { |
72 |
| - ctx.canvas.width = canvas.offsetWidth; |
73 |
| - ctx.canvas.height = canvas.offsetHeight; |
74 |
| - } |
75 |
| -} |
| 70 | + function setCanvasSize() { |
| 71 | + if (ctx) { |
| 72 | + ctx.canvas.width = canvas.offsetWidth; |
| 73 | + ctx.canvas.height = canvas.offsetHeight; |
| 74 | + } |
| 75 | + } |
76 | 76 |
|
77 |
| -function goBack() { |
78 |
| - history.back(); |
79 |
| -} |
| 77 | + function goBack() { |
| 78 | + history.back(); |
| 79 | + } |
80 | 80 |
|
81 |
| -document.querySelector('#backButton').addEventListener('click', goBack); |
| 81 | + document.querySelector('#backButton').addEventListener('click', goBack); |
82 | 82 |
|
83 |
| -window.addEventListener('resize', setCanvasSize); |
| 83 | + window.addEventListener('resize', setCanvasSize); |
84 | 84 |
|
85 |
| -ctx = canvas.getContext('2d'); |
| 85 | + ctx = canvas.getContext('2d'); |
86 | 86 |
|
87 |
| -ctx.canvas.width = canvas.offsetWidth; |
88 |
| -ctx.canvas.height = canvas.offsetHeight; |
| 87 | + ctx.canvas.width = canvas.offsetWidth; |
| 88 | + ctx.canvas.height = canvas.offsetHeight; |
89 | 89 |
|
90 |
| -const speed = { x: 2, y: 2 }; |
91 |
| -const pos = { |
92 |
| - x: random(64, canvas.width - 64), |
93 |
| - y: random(64, canvas.height - 64) |
94 |
| -}; |
| 90 | + const speed = { x: 2, y: 2 }; |
| 91 | + const pos = { |
| 92 | + x: random(64, canvas.width - 64), |
| 93 | + y: random(64, canvas.height - 64) |
| 94 | + }; |
95 | 95 |
|
96 |
| -let frame = requestAnimationFrame(loop); |
| 96 | + let frame = requestAnimationFrame(loop); |
97 | 97 |
|
98 |
| -function loop() { |
99 |
| - frame = requestAnimationFrame(loop); |
| 98 | + function loop() { |
| 99 | + frame = requestAnimationFrame(loop); |
100 | 100 |
|
101 |
| - ctx.clearRect(0, 0, canvas.width, canvas.height); |
| 101 | + ctx.clearRect(0, 0, canvas.width, canvas.height); |
102 | 102 |
|
103 |
| - pos.x += speed.x; |
104 |
| - pos.y += speed.y; |
| 103 | + pos.x += speed.x; |
| 104 | + pos.y += speed.y; |
105 | 105 |
|
106 |
| - // collisions |
107 |
| - if (pos.x <= 32 || pos.x + 32 >= canvas.width) { |
108 |
| - speed.x *= -1; |
109 |
| - } |
| 106 | + // collisions |
| 107 | + if (pos.x <= 32 || pos.x + 32 >= canvas.width) { |
| 108 | + speed.x *= -1; |
| 109 | + } |
110 | 110 |
|
111 |
| - if (pos.y <= 32 || pos.y + 28 >= canvas.height) { |
112 |
| - speed.y *= -1; |
113 |
| - } |
| 111 | + if (pos.y <= 32 || pos.y + 28 >= canvas.height) { |
| 112 | + speed.y *= -1; |
| 113 | + } |
114 | 114 |
|
115 |
| - // oob |
116 |
| - if (pos.x < 0 || pos.x > canvas.width || pos.y < 0 || pos.y > canvas.height) { |
117 |
| - pos.x = canvas.width / 2; |
118 |
| - pos.y = canvas.height / 2; |
119 |
| - } |
| 115 | + // oob |
| 116 | + if (pos.x < 0 || pos.x > canvas.width || pos.y < 0 || pos.y > canvas.height) { |
| 117 | + pos.x = canvas.width / 2; |
| 118 | + pos.y = canvas.height / 2; |
| 119 | + } |
120 | 120 |
|
121 |
| - // set size of the emoji and the font |
122 |
| - ctx.font = '64px Arial'; |
123 |
| - // use these alignment properties for "better" positioning |
124 |
| - ctx.textAlign = 'center'; |
125 |
| - ctx.textBaseline = 'middle'; |
| 121 | + // set size of the emoji and the font |
| 122 | + ctx.font = '64px Arial'; |
| 123 | + // use these alignment properties for "better" positioning |
| 124 | + ctx.textAlign = 'center'; |
| 125 | + ctx.textBaseline = 'middle'; |
126 | 126 |
|
127 |
| - // draw the emoji |
128 |
| - ctx.fillText('🦝', pos.x, pos.y); |
129 |
| -} |
| 127 | + // draw the emoji |
| 128 | + ctx.fillText('🦝', pos.x, pos.y); |
| 129 | + } |
130 | 130 |
|
131 |
| -// onUnmounted(() => { |
132 |
| -// window.removeEventListener(setCanvasSize); |
133 |
| -// cancelAnimationFrame(frame); |
134 |
| -// }); |
| 131 | + // onUnmounted(() => { |
| 132 | + // window.removeEventListener(setCanvasSize); |
| 133 | + // cancelAnimationFrame(frame); |
| 134 | + // }); |
135 | 135 | </script>
|
136 | 136 |
|
137 | 137 | <style lang="postcss">
|
|
0 commit comments