-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
506 lines (444 loc) · 14.4 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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
<!DOCTYPE html>
<!--
ABOUT
This project was programmed for the IT-Talents programming contest 2017
(https://www.it-talents.de/foerderung/code-competition/code-competition-09-2017)
by Johannes Vollmer.
Unfortunately, four days before the end of the contest, my laptop broke.
This project was 'finished' with the macbook of a friend.
All expensive operations (including applying the rules and displaying the board)
are computed on the GPU, using WebGL.
This will improve performance a lot on most devices.
-->
<!--
Ideas for future development
- enable flipping brushes horizontally and vertically
- serialize the game rules to exported svg!
- include rule-presets in the settings panel
- 'about this project' info
- let users create custom brushes to save intereting shapes
- restrict panning so that you cannot pan away the board
-->
<html>
<head>
<meta charset="utf-8">
<title>WebGL Of Life by Johannes Vollmer</title>
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style/main_layout.css">
<link rel="stylesheet" href="style/dark_theme.css">
</head>
<body>
<p id="no-js-warning">
<!--
This warning removes itself, if JS is enabled.
If disabled, it keeps showing that JS must be enabled.
-->
This website requires JavaScript to do anything interesting.
<script type="text/javascript">
const noJsWarning = document.getElementById('no-js-warning')
noJsWarning.parentElement.removeChild(noJsWarning)
</script>
</p>
<canvas id="gl">
<!--
Main OpenGL Canvas.
Is always 100% width and height of screen,
because some old browsers like chrome 61 or firefox 52
still do not support converting between global and local
mouse coordinates in 2018
(by using 100% screensize we can always use global coordinates)
-->
You must enable WebGL to use this Website
</canvas>
<!--
contains everything except the canvas
and will be overlayed like a head up display
-->
<main>
<!--
the panel on the left
which can be shown/hidden with tab or by clicking on the pen symbol.
contains the ui for painting onto the board, including
- clearing the board
- randomizing the board
- choosing a pattern for painting
- import / export as svg
- changing board size
-->
<div id="brush" class="hidden panel">
<section>
<p>Board</p>
<div class="grid">
<label>
<!--
This input will provide core functionality
(for example keeping track if it is checked),
but we will hide it and display an svg instead
-->
<input type="button" class="hidden" id="clear-board"/>
<!-- this will be shown instead of the default input -->
<img src="style/img/clear.svg" class="button">
<!-- tooltip, visible when the user hovers the svg.button -->
<p class="tooltip">
<b>Clear</b><br>
Remove all living cells
</p>
</label>
<label>
<input type="button" class="hidden" id="randomize-board"/>
<img src="style/img/randomize.svg" class="button">
<p class="tooltip">
<b>Randomize</b><br>
Generate a random pattern of cells
</p>
</label>
</div>
</section>
<section>
<p id="pattern-header">Pattern</p>
<div id="patterns" class="grid">
<!-- to be filled with labels in js -->
</div>
</section>
<section>
<p>Pattern Mode</p>
<div class="grid">
<label>
<input type="radio" name="cellmode" class="hidden"
id="pattern-mode-invert" checked
>
<img src="style/img/invert.svg" class="button">
<p class="tooltip">
<b>Invert Cells</b><br>
For every cell of the pattern,<br>
invert the life status of the<br>
underlying cell on the board
</p>
</label>
<label>
<input type="radio" name="cellmode" class="hidden"
id="pattern-mode-add"
>
<img src="style/img/add.svg" class="button">
<p class="tooltip">
<b>Add Cells</b><br>
For every cell of the pattern,<br>
revive the underlying cell on the board
</p>
</label>
<label>
<input type="radio" name="cellmode" class="hidden"
id="pattern-mode-remove"
>
<img src="style/img/remove.svg" class="button">
<p class="tooltip">
<b>Remove Cells</b><br>
For every cell of the pattern,<br>
remove the underlying cell on the board
</p>
</label>
</div>
</section>
<section>
<p>Load and Save</p>
<div class="file grid">
<label>
<input id="load-svg" name="files[]" accept="image/xml+svg"
type="file" class="hidden"
>
<img src="style/img/load.svg" class="button">
<p class="tooltip">
<b>Load SVG</b><br>
Load a board from an SVG file
</p>
</label>
<label>
<input type="button" id="save-svg" value="Save SVG"
class="hidden"
>
<img src="style/img/save.svg" class="button">
<p class="tooltip">
<b>Save SVG</b><br>
Save the board to an SVG file
</p>
</label>
</div>
</section>
<section>
<p>Board Size</p>
<label>
<input type="number" id="board-width" value="600" min="1"
class="number button"
>
<p class="tooltip">
<b>Board Width</b><br>
The number of cells living in a row.<br>
Should be between 1 and 4000, depending on your computer's memory.
</p>
</label>
<label>
<input type="number" id="board-height" value="400" min="1"
class="number button"
>
<p class="tooltip">
<b>Board Height</b><br>
The number of cells living in a column.<br>
Should be between 1 and 4000, depending on your computer's memory.
</p>
</label>
</section>
</div>
<!--
the panel on the right
which can be shown/hidden by clicking on the settings symbol.
contains the ui for various settings, including
- changing the game rules
- changing animation speed
-->
<div id="settings" class="hidden panel">
<section>
<p id="survive-rules-header">Survive Rules</p>
<div class="grid" id="survive-rules">
<script type="text/javascript">
for(let i = 0; i < 9; i++){
const unit = (i == 1)? 'neighbour' : 'neighbours'
const checked = (i == 2 || i == 3)? 'checked' : ''
document.write(`
<label>
<input id="survive-${i}" type="checkbox"
name="survive-${i}" class="hidden"
${checked}
/>
<p class="rule button">${i}</p>
<p class="tooltip">
<b>Survive with ${i} ${unit}</b><br>
If enabled, any cell with ${i} ${unit} will remain living
</p>
</label>
`)
}
</script>
</div>
</section>
<section>
<p id="revive-rules-header">Revive Rules</p>
<div class="grid" id="revive-rules">
<script type="text/javascript">
for(let i = 0; i < 9; i++){
const unit = (i == 1)? 'neighbour' : 'neighbours'
const checked = (i == 3)? 'checked' : ''
document.write(`
<label>
<input id="revive-${i}" type="checkbox"
name="revive-${i}" class="hidden"
${checked}
/>
<p class="rule button">${i}</p>
<p class="tooltip">
<b>Revive with ${i} ${unit}</b><br>
If enabled, any cell with ${i} ${unit} will become alive
</p>
</label>
`)
}
</script>
</div>
</section>
<section>
<p>Animation Speed</p>
<label>
<input id="speed" type="number" name="speed" value="300"
class="number button" step="0.1" min="0" max="5000"
>
<p class="tooltip">
<b>Animation Speed</b><br>
In generations per second.<br>
Values should be between 0 and 5000, depending on the grid size.
</p>
</label>
</section>
<section>
<p>View</p>
<div class="grid">
<label>
<input id="transition" type="checkbox" name="transition"
class="hidden" checked
>
<img src="style/img/transition.svg" class="button">
<p class="tooltip">
<b>Transition</b><br>
Blend between the generations
to create smooth transitions.
</p>
</label>
<label>
<input type="checkbox" class="hidden" id="grid-view"
name="grid-view" checked
>
<img src="style/img/grid.svg" class="button">
<p class="tooltip">
<b>Checkerboard</b>
<span class="info">[C]</span>
<br>Overlay a checkerboard when zoomed in closely
</p>
</label>
<label>
<input type="button" class="hidden" id="reset-view"/>
<img src="style/img/focus.svg" class="button">
<p class="tooltip">
<b>Reset</b>
<span class="info">[F]</span>
<br>Reset the view to the center of the board
</p>
</label>
</div>
</section>
<section>
<p>Cell Mode</p>
<div class="grid">
<label>
<input type="radio" class="hidden" name="life" id="life-view"
checked
>
<img src="style/img/life.svg" class="button">
<p class="tooltip">
<b>Cell Mode: Life</b>
<span class="info">[1]</span>
<br>Show if a cell is alive (red) or dead (blue)
</p>
</label>
<label>
<input type="radio" class="hidden" name="life" id="activity-view">
<img src="style/img/activity.svg" class="button">
<p class="tooltip">
<b>Cell Mode: Activity</b>
<span class="info">[2]</span>
<br>Show where a cell was born (white) or killed (red)
</p>
</label>
<label>
<input type="radio" class="hidden" name="life" id="neighbour-view">
<img src="style/img/cluster.svg" class="button">
<p class="tooltip">
<b>Cell Mode: Neighbours</b>
<span class="info">[3]</span>
<br>Show how many neighbours a cell has (warmer color means more neighbours)
</p>
</label>
</div>
</section>
<section>
<p>Zoom Sensitivity</p>
<label>
<input id="sensitivity" type="number" name="sensitivity" value="100"
class="number button" step="10" min="0" max="1000"
>
<p class="tooltip">
<b>Zoom Sensitivity</b><br>
How fast zooming will work. Default is 100.
</p>
</label>
</section>
<section>
<p>Generation</p>
<p>
Displaying #
<span id="generation-value">0</span>
</p>
</section>
<section>
<p>About</p>
<label>
<input type="button" value="Read More" class="hidden" >
<!-- TODO: insert some margin via css -->
<a class="button" href="http://johannesvollmer.github.io">Read More</a>
</label>
</section>
<br> <!-- TODO: use margin via css -->
</div>
<!--
contains the ui for playback and showing/hiding the other two panels
-->
<header id="toolbar">
<div>
<label>
<input type="checkbox" class="hidden" id="paint" name="paint"/>
<img src="style/img/pen.svg" class="button">
<p class="tooltip below">
<b>Game: Paint</b>
<span class="info">[Tab]</span>
<br>Paint cells onto the board, resize it, and import or export the board
</p>
</label>
</div>
<div>
<label>
<input type="button" class="hidden" id="reset-time"/>
<img src="style/img/reset.svg" class="button">
<p class="tooltip below">
<b>Generation: Reset</b>
<span class="info">[Escape]</span>
<br>Reset the board to the first generation
</p>
</label><!-- this comment prevents whitespace
--><label>
<input type="checkbox" class="hidden" id="animate-time"
name="animate-time"
>
<div class="button">
<img id="play" src="style/img/play.svg" >
<img id="pause" src="style/img/pause.svg">
</div>
<p class="tooltip below">
<b>Generation: Animate</b>
<span class="info">[Spacebar]</span>
<br>Continuously apply the rules to the board
</p>
</label><!-- this comment prevents whitespace
--><label>
<input type="button" class="hidden" id="increment-time"/>
<img src="style/img/increment.svg" class="button">
<p class="tooltip below">
<b>Generation: Increase</b>
<span class="info"> [Ctrl + Spacebar]</span>
<br>Apply the rules to the board once
</p>
</label>
</div>
<label>
<input type="checkbox" class="hidden" id="show-settings"/>
<img src="style/img/sliders.svg" class="button">
<p class="tooltip below">
<b>Settings: Show Settings</b><br>
Show various options, <br>including
the game rules, animation speed,
grid visibility and more.
</p>
</label>
</header>
</main>
<!-- generic dom and js scripts -->
<script type="text/javascript" src="js/CreateElement.js"></script>
<script type="text/javascript" src="js/ScaleAndDragDetector.js"></script>
<script type="text/javascript" src="js/Timer.js"></script>
<!-- webgl abstraction wrapper scripts -->
<script type="text/javascript" src="js/gl/Material.js"></script>
<script type="text/javascript" src="js/gl/Texture.js"></script>
<script type="text/javascript" src="js/gl/TriangleStrip.js"></script>
<script type="text/javascript" src="js/gl/OffscreenRenderer.js"></script>
<!-- actual game of life scripts -->
<script type="text/javascript" src="js/cell/CellConvolutionShader.js"></script>
<script type="text/javascript" src="js/cell/CellRenderingShader.js"></script>
<script type="text/javascript" src="js/cell/CellNeighbourShader.js"></script>
<script type="text/javascript" src="js/cell/CellBoard.js"></script>
<script type="text/javascript" src="js/cell/CellBoardView.js"></script>
<script type="text/javascript" src="js/cell/CellPainter.js"></script>
<script type="text/javascript" src="js/cell/BrushRenderingShader.js"></script>
<script type="text/javascript" src="js/cell/CellPainterPreview.js"></script>
<script type="text/javascript" src="js/cell/DefaultPatterns.js"></script>
<script type="text/javascript" src="js/cell/PatternThumbnails.js"></script>
<!-- app scripts -->
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript"> setup() </script>
</body>
</html>