-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
258 lines (221 loc) · 11.2 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
<!DOCTYPE html>
<html>
<head>
<meta charset = utf-8>
<meta name = viewport content = 'width = device-width, initial-scale = 1'>
<meta name = keywords content = 'Joachim Ford, JavaScript games, Indie game dev'>
<meta name = description content = 'A base of fully-featued indie games and experiments'>
<script async src = 'https://www.googletagmanager.com/gtag/js?id=G-2MDQ9F697V'></script>
<script src = /js/analytics.js></script>
<script src = /js/main.js></script>
<title>Joachim Ford</title>
<link rel = stylesheet href = /main.css>
<link rel = icon type = image/x-icon href = /favs/favicon.ico>
<style>
html {height: 100%}
body {
margin: 0;
padding: 0;
overflow: hidden;
width: 100%;
height: 100%;
max-width: none;
}
canvas {
width: 100%;
height: 100%;
}
.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 = /experiments>Experiments</a>
<a href = /articles>Articles</a>
<a href = /news>News</a>
</div>
</section>
<section class = main>
<a href = /content/squirtcopter id = link><canvas id = cvs></canvas></a>
<script>
function resize() {
cvs.width = innerWidth * devicePixelRatio
cvs.height = innerHeight * devicePixelRatio + 1
box = cvs.width
if (cvs.width > cvs.height) box = cvs.height
}
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 update() {
ctx.clearRect(0, 0, cvs.width, cvs.height)
let dt = (performance.now() - oldPerf) / 16
oldPerf = performance.now()
if (dt > 1) dt = 1
time += speed * dt
initTime += speed * dt
const img = images[active]
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
}
if (changeImage > .5) link.href = images[active].url
if (changeImage >= 1) changeImage = 0
let imgPosX = cvs.width / 2 - w / 2
const imgPosY = cvs.height / 2 - h / 2 + 60 * devicePixelRatio
if (changeImage) {
changeImage += speed * changeImageSpeed
imgPosX -= quad(Math.sin(changeImage * Math.PI / 2)) * w
ctx.drawImage(img, imgPosX + w, imgPosY, w, h)
let last = active - 1
if (last < 0) last = images.length - 1
ctx.drawImage(images[last], imgPosX, imgPosY, w, h)
}
else ctx.drawImage(img, imgPosX, imgPosY, w, h)
let a = (500-initTime)/500
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,.4)
const boxW = cvs.width
const boxH = h / 3
const yPos = cvs.height / 2 + 100 - cvs.height / 4.5
if (changeImage) {
let posX = cvs.width / 2 - boxW / 2 - quad(Math.sin(changeImage * Math.PI / 2)) * w
ctx.fillRect(posX, yPos, boxW, boxH)
ctx.fillRect(posX + w, 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
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
if (item.expire && check > item.time) {
summ = 20 - (check - item.time)
if (summ < 0) summ = 0
}
for (let i = 0; i < item.name.length; i ++) {
ctx.font = S + 'px pixelMonospace, impact, monospace, sans-serif'
const posX = item.x * (add * .7) + cvs.width / 2 - add / 6.5
const posY = item.y * (add * .3) + cvs.height / 2 + 100 - add / 40
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)
}
ctx.fillStyle = rgb(1,1,1,summ/3-(Math.sin(i*i)+1))
ctx.fillText(
item.name[i],
posX + i * gap + Math.cos(summ) * shake,
posY + Math.sin(summ) * shake)
}
}
}
ctx.fillStyle = rgb(1,1,.4,
Math.sin(time / 247 +
Math.cos(time / 133) * 2 +
Math.sin(time / 17) * .1) * .2)
ctx.fillRect(
cvs.width / 2 + Math.sin(time / 330 + Math.cos(time / 500)) * cvs.width / 3,
cvs.height / 2 + Math.cos(time / 230 + Math.sin(time / 550)) * cvs.height / 3,
box * .03, box * .03)
requestAnimationFrame(update)
}
const ctx = cvs.getContext('2d')
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 images = []
const makeNewImage = (name, url) => {
const img = new Image()
img.src = 'images/'+name+'.png'
img.url = url
images.push(img)
}
makeNewImage('squirtcopter_big', '/content/squirtcopter')
makeNewImage('ios_mission_big', '/content/ios_mission')
makeNewImage('bg2', '/content/canvas_craft')
const booms = [
{name: 'SQUIRTCOPTER', time: 70, x: 0, y: 0, size: .03, expire: 35},
{name: 'By Joachim Ford', time: 100, x: 0, y: .1, size: .01, expire: 100},
{name: 'SQUIRTCOPTER', time: 100, x: 0, y: 0, size: .03, expire: 215},
{name: 'Squirt Your Way To Victory!', time: 205, x: 0, y: .1, size: .01, expire: 100},
{name: 'Switch', time: 350},
{name: 'IO\'S MISSION', time: 370, x: 0, y: 0, size: .03, expire: 225},
{name: '..', time: 425, x: 0, y: .1, size: .01, expire: 2},
{name: '..........', time: 430, x: 0, y: .1, size: .01, expire: 2},
{name: '........................', time: 435, x: 0, y: .1, size: .01, expire: 2},
{name: 'The Online Adventure Game', time: 440, x: 0, y: .1, size: .01, expire: 140},
{name: 'Switch', time: 650},
{name: 'CANVASCRAFT', time: 700, x: 0, y: 0, size: .03, expire: 215},
{name: '"Where Craft and Code Collide"', time: 705, x: 0, y: .08, size: .01, expire: 200},
{name: 'canvas', time: 800, x: 0, y: .14, size: .01, expire: 2},
{name: 'canvas-craft', time: 808, x: 0, y: .14, size: .01, expire: 2},
{name: 'canvas-craft.github', time: 812, x: 0, y: .14, size: .01, expire: 2},
{name: 'canvas-craft.github.io', time: 825, x: 0, y: .14, size: .01, expire: 100},
{name: 'Switch', time: 950}
]
addEventListener('resize', resize)
resize()
update()
</script>
</section>
<button class = theme onclick = toggleTheme()>Change Theme</button>
<span class = copyright>
© Copyright <span class = year></span> joachimford.uk
<a href = https://github.com/Hope41 target = _blank><img src = /svg/github.svg></img></a>
<a href = mailto:[email protected]><img src = /svg/mail.svg></img></a>
</span>
</body>
</html>