-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
300 lines (258 loc) · 13 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
<!DOCTYPE html>
<html lang = en-gb>
<head>
<meta charset = utf-8>
<meta name = viewport content = 'width = device-width, initial-scale = 1'>
<meta name = description content = 'Free online coding blogs and open source games'>
<script async src = 'https://www.googletagmanager.com/gtag/js?id=G-2MDQ9F697V'></script>
<script src = /src/js/analytics.js></script>
<script src = /src/js/main.js></script>
<title>Coding Blogs and Indie Games | Joachim Ford</title>
<link rel = stylesheet href = /src/main.css>
<link rel = icon type = image/x-icon href = /src/favs/favicon.ico>
<style>
html {height: 100%}
body {
margin: 0;
padding: 0;
overflow: hidden;
width: 100%;
height: 100%;
max-width: none;
}
canvas {
display: inline-block;
width: 100%;
position: fixed;
top: 60px;
background-color: #000;
}
.main {
margin: 0;
padding: 0;
max-width: none;
}
</style>
</head>
<body>
<section class = topnav>
<div class = title>
<a class = brand href = '/'>Joachim Ford</a>
<a class = about href = /about>About</a>
</div>
<div class = nav>
<a href = /games>Games</a>
<a href = /projects>Projects</a>
<a href = /blogs>Blogs</a>
<a href = /news>News</a>
</div>
</section>
<a href = /src/content/squirtcopter id = link><canvas id = cvs></canvas></a>
<section class = main>
<script>
const topnav = document.getElementsByClassName('topnav')[0]
let toph = 0
function resize() {
toph = topnav.getBoundingClientRect().height
cvs.width = innerWidth * devicePixelRatio
cvs.height = (innerHeight - toph + 1) * devicePixelRatio
cvs.style.top = toph + 'px'
}
function rgb(r, g, b, a = 1) {
return 'rgb('+(r*255)+','+(g*255)+','+(b*255)+','+a+')'
}
function quad(x) {
return x < .5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2
}
function drawImage(img, x, y, w, h) {
ctx.fillStyle = img.color
ctx.fillRect(x - w / 2, 0, w, cvs.height)
if (img.complete) {
if (img.init) img.alpha = 1
else if (img.complete && img.alpha < 1) img.alpha += .01 * dt
}
ctx.globalAlpha = img.alpha
ctx.drawImage(img, x - w / 2, y - h / 2, w, h)
ctx.globalAlpha = 1
img.init = false
}
function update() {
ctx.clearRect(0, 0, cvs.width, cvs.height)
dt = (performance.now() - oldPerf) / 16
oldPerf = performance.now()
if (dt > 1) dt = 1
time += speed * dt
initTime += speed * dt
const img = images[active]
box = cvs.width
if (cvs.width > cvs.height) box = cvs.height
const iRatio = img.width / img.height
const cRatio = cvs.width / cvs.height
let w = 0
let h = 0
if (iRatio < cRatio) {
w = cvs.width
h = (img.height / img.width) * cvs.width
}
else {
w = iRatio * cvs.height
h = cvs.height
}
const amt = quad(Math.sin(changeImage * Math.PI)) / 6
box *= 1 - amt * bannerZ
w *= 1 - amt * bgZ
h *= 1 - amt * bgZ
if (changeImage > .5) link.href = images[active].url
if (changeImage >= 1) changeImage = 0
let imgPosX = cvs.width / 2
const imgPosY = cvs.height / 2
if (changeImage) {
changeImage += speed * changeImageSpeed * dt
imgPosX -= quad(Math.sin(changeImage * Math.PI / 2)) * w
drawImage(img, imgPosX + w, imgPosY, w, h)
ctx.fillStyle = img.color
ctx.fillRect(imgPosX + w * 1.5, 0, w, cvs.height)
let last = active - 1
if (last < 0) last = images.length - 1
drawImage(images[last], imgPosX, imgPosY, w, h)
}
else drawImage(img, imgPosX, imgPosY, w, h)
let a = (400-initTime)/400
if (a < .4) a = .4
ctx.fillStyle = rgb(0,0,0,a)
ctx.fillRect(0, 0, cvs.width, cvs.height)
ctx.fillStyle = rgb(0,0,0,.6)
const boxW = cvs.width * (1 - amt)
const boxH = box / 3
const midY = cvs.height / 2
const yPos = midY - boxH / 2
if (changeImage) {
let posX = cvs.width / 2 - boxW / 2 - quad(Math.sin(changeImage * Math.PI / 2)) * w * bannerZ
ctx.fillRect(posX, yPos, boxW, boxH)
ctx.fillRect(posX + w * bannerZ, yPos, boxW, boxH)
}
else ctx.fillRect(cvs.width / 2 - boxW / 2, yPos, boxW, boxH)
for (let j = 0; j < booms.length; j ++) {
const item = booms[j]
const sum = time - item.time
if (sum > 0) {
if (item.name == 'Switch') {
if (progress >= j) continue
progress = j
active ++
changeImage += speed * changeImageSpeed * dt
if (active > images.length - 1) {
time = 0
active = 0
progress = 0
}
continue
}
const add = box * 3
const S = (add * item.size)
const gap = S * .82
const size = item.name.length * gap
let summ = sum
const check = time - item.expire
const calc = check - item.time
if (item.expire && check > item.time) {
summ = 20 - calc
if (summ < 0) summ = 0
}
for (let i = 0; i < item.name.length; i ++) {
ctx.font = S + 'px pixelMonospace, monospace, sans-serif'
const bobX = Math.cos(i * i * i) * S * .03
const bobY = Math.sin(i * i) * S * .03
const posX = item.x * (add * .7) + cvs.width / 2 - add / 6.5 + bobX
const posY = item.y * (add * .3) + midY - add / 200 + bobY
const shake = 99 / (summ * summ * .5) * 5
if (shake > 8) {
let r = Math.sin(i*i*9*j)
let g = Math.sin(i*i*i*i*j*j*9)
let b = Math.sin(i*i*i**j)
ctx.fillStyle = rgb(r,g,b,summ/5-(Math.sin(i*i)+1))
ctx.fillText(
item.name[i],
posX + i * gap - Math.cos(summ) * shake,
posY - Math.sin(summ) * shake)
}
const tx = posX + i * gap + Math.cos(summ) * shake
const ty = posY + Math.sin(summ) * shake
ctx.fillStyle = rgb(0,0,0,1-calc/10)
ctx.fillText(item.name[i], tx + S * .05, ty + S * .1)
const rot = calc / 5 / (summ * summ * Math.sin(i * i * i * i + 1))
ctx.fillStyle = rgb(1,1,1,summ/3-(Math.sin(i*i)+1)-rot)
ctx.save()
ctx.translate(tx + gap / 2, ty - gap / 2)
ctx.rotate(Math.sin(i*i*i)*.2*rot)
ctx.fillText(item.name[i], -gap / 2, gap / 2)
ctx.restore()
}
}
}
ctx.fillStyle = rgb(1,1,.4,
Math.sin(initTime / 247 +
Math.cos(initTime / 133) * 2 +
Math.sin(initTime / 17) * .1) * .15 + .1)
ctx.fillRect(
cvs.width / 2 + Math.sin(initTime / 330 + Math.cos(initTime / 500)) * cvs.width / 3,
cvs.height / 2 + Math.cos(initTime / 230 + Math.sin(initTime / 550)) * cvs.height / 3,
box * .03, box * .03)
requestAnimationFrame(update)
}
const ctx = cvs.getContext('2d')
let dt = 0
let time = 0
let initTime = 0
let active = 0
let box = 0
let changeImage = 0
let oldPerf = 0
let progress = -1
const changeImageSpeed = .012
const speed = 1.2
const bgZ = 1
const bannerZ = 2
const images = []
const makeNewImage = (name, url, color) => {
const img = new Image()
img.src = '/src/images/'+name+'.png'
img.url = url
img.color = color
img.alpha = 0
img.init = true
images.push(img)
}
makeNewImage('squirtcopter_big', '/src/content/squirtcopter', '#756')
makeNewImage('ios_mission_big', '/src/content/ios_mission', '#79b')
makeNewImage('snakes_and_ladders_big', '/src/content/snakes_and_ladders', '#8ca')
const booms = [
{name: 'SQUIRTCOPTER', time: 70, x: 0, y: 0, size: .03, expire: 30},
{name: 'SQUIRTCOPTER', time: 100, x: 0, y: 0, size: .03, expire: 220},
{name: 'Squirt Your Way To Victory!', time: 115, x: 0, y: .1, size: .01, expire: 195},
{name: 'Switch', time: 350},
{name: 'IO\'S MISSION', time: 450, x: 0, y: 0, size: .03, expire: 280},
{name: '..', time: 500, x: 0, y: .1, size: .01, expire: 2},
{name: '..........', time: 505, x: 0, y: .1, size: .01, expire: 2},
{name: '........................', time: 510, x: 0, y: .1, size: .01, expire: 2},
{name: 'The New Adventure Game', time: 515, x: 0, y: .1, size: .01, expire: 220},
{name: 'Switch', time: 750},
{name: 'SNAKES', time: 850, x: 0, y: -.01, size: .025, expire: 2},
{name: 'SNAKES AND', time: 855, x: 0, y: -.01, size: .025, expire: 320},
{name: 'LADDERS', time: 860, x: .2, y: .07, size: .025, expire: 320},
{name: 'Defeat the X-Ray Orb!', time: 930, x: 0, y: .13, size: .01, expire: 240},
{name: 'Switch', time: 1200}
]
addEventListener('resize', resize)
resize()
update()
</script>
</section>
<button class = theme onclick = toggleTheme()>Change Theme</button>
<span class = copyright>
© <span class = year></span> Joachim Ford. All rights reserved.
<a href = https://github.com/Hope41 target = _blank><img src = /src/images/github.svg></img></a>
<a href = mailto:[email protected]><img src = /src/images/mail.svg></img></a>
</span>
</body>
</html>