-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
301 lines (243 loc) · 9.17 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
<!DOCTYPE html>
<head>
<meta charset = utf-8>
<script async src = 'https://www.googletagmanager.com/gtag/js?id=G-2MDQ9F697V'></script>
<script src = /js/analytics.js></script>
<title>Infinite Zoom</title>
<style>
body {
background: #222;
margin: 0;
overflow: hidden;
}
canvas {
cursor: none
}
</style>
</head>
<body>
<canvas id = cvs></canvas>
<script>
'use strict'
class Map {
constructor() {
this.array = []
this.scale = 1.01
this.set()
}
set() {
const start_size = (cvs.width + cvs.height) / 30
this.addNewShape(
cvs.width / 2 - start_size / 2 * shape.size,
cvs.height / 2 - start_size / 2 * shape.size,
start_size
)
}
addNewShape(x, y, size) {
// add a single shape to the map
this.array.push(
new Shape(
x, y, size
)
)
}
addNewShapes(x, y, size) {
// add multiple shapes inside the previous
const width = shape.size
for (let i = 0; i < width * width; i ++) {
if (shape.arr[i]) {
this.addNewShape(
x + (i % width) * size,
y + ~~(i / width) * size,
size / width
)
}
}
}
update() {
for (let i = 0; i < this.array.length; i ++) {
const item = this.array[i]
if (item.die) {
this.array.splice(i, 1)
i --
}
item.update(i)
}
}
}
class Shape {
constructor(x, y, size) {
this.x = x
this.y = y
// size is the width & height of the entire shape
this.size = size
this.die = false
this.fade = false
this.alpha = 1
}
update() {
const max = (cvs.width + cvs.height) / 100
if (this.fade) {
this.alpha -= .05
if (this.alpha <= 0) this.die = true
}
else if (this.size > max) {
map.addNewShapes(
this.x,
this.y,
this.size
)
this.fade = true
}
this.draw()
this.x -= mouse.x * (map.scale - 1)
this.y -= mouse.y * (map.scale - 1)
this.x *= map.scale
this.y *= map.scale
this.size *= map.scale
if (this.x < -shape.size * this.size ||
this.x > cvs.width ||
this.y < -shape.size * this.size ||
this.y > cvs.height) {
this.die = true
}
}
draw() {
let total = this.alpha - alpha
if (total < 0) total = 0
ctx.globalAlpha = total
ctx.drawImage(
icon_cvs,
this.x,
this.y,
this.size * shape.size,
this.size * shape.size
)
ctx.globalAlpha = 1
}
}
function indexToPos(index, width) {
return {
x: index % width,
y: ~~(index / width)
}
}
function random(min, max, int = 1) {
const value = Math.random() * (max - min) + min
return int ? Math.floor(value) : value
}
function rgb(red, green, blue, alpha = 1) {
return `rgb(${red}, ${green}, ${blue}, ${alpha})`
}
function move(e) {
mouse.x = e.clientX
mouse.y = e.clientY
mouse.auto = false
}
function resize() {
cvs.width = innerWidth
cvs.height = innerHeight
ctx.imageSmoothingEnabled = false
}
function update() {
ctx.clearRect(0, 0, cvs.width, cvs.height)
map.update()
ctx.fillStyle = '#fff'
ctx.strokeStyle = '#000'
ctx.lineWidth = 1.5
ctx.save()
ctx.translate(mouse.x, mouse.y)
ctx.beginPath()
ctx.moveTo(0, 0)
ctx.lineTo(0, 15)
ctx.lineTo(4, 13)
ctx.lineTo(7, 18)
ctx.lineTo(9.5, 17)
ctx.lineTo(7, 12)
ctx.lineTo(12, 11)
ctx.closePath()
ctx.stroke()
ctx.fill()
ctx.restore()
if (mouse.auto && map.array.length) {
const obj = map.array[Math.floor(map.array.length / 2)]
const dist_x = (obj.x + obj.size / 2) - mouse.x
const dist_y = (obj.y + obj.size / 2) - mouse.y
mouse.speed.x += dist_x
mouse.speed.y += dist_y
mouse.speed.x *= .9
mouse.speed.y *= .9
// increase the number for weaker movements
const s = (cvs.width + cvs.height) / 2e5
mouse.x += mouse.speed.x * s
mouse.y += mouse.speed.y * s
}
if (!map.array.length) {
alpha = 1
mouse.auto = true
map.array = []
map.set()
}
if (alpha > 0) alpha -= .007
else alpha = 0
// vignette
const size = (cvs.width + cvs.height) / 4
const grad = ctx.createRadialGradient(
cvs.width / 2,
cvs.height / 2,
size * .3,
cvs.width / 2,
cvs.height / 2,
size)
grad.addColorStop(0, '#0000')
grad.addColorStop(1, '#000')
ctx.fillStyle = grad
ctx.fillRect(0, 0, cvs.width, cvs.height)
requestAnimationFrame(update)
}
const ctx = cvs.getContext('2d')
const icon_cvs = document.createElement('canvas')
const icon_ctx = icon_cvs.getContext('2d')
const shape = {
arr: [
0,1,1,1,0,0,
1,0,1,0,1,0,
1,1,1,1,1,0,
1,0,0,0,1,0,
0,1,1,1,0,0,
0,0,0,0,0,0
],
size: 6
}
icon_cvs.width = shape.size * shape.size
icon_cvs.height = shape.size * shape.size
for (let a = 0; a < shape.size * shape.size; a ++) {
if (shape.arr[a]) {
const Xa = a % shape.size
const Ya = Math.floor(a / shape.size)
for (let b = 0; b < shape.size * shape.size; b ++) {
if (shape.arr[b]) {
const Xb = b % shape.size
const Yb = Math.floor(b / shape.size)
icon_ctx.fillStyle = '#3f5'
icon_ctx.fillRect(Xa * shape.size + Xb, Ya * shape.size + Yb, 1, 1)
}
}
}
}
let alpha = 0
addEventListener('resize', resize)
addEventListener('mousemove', move)
addEventListener('pointerdown', move)
resize()
const map = new Map()
const mouse = {
x: cvs.width / 2,
y: cvs.height / 2,
speed: {x: 0, y: 0},
auto: true
}
update()
</script>
</body>
</html>