-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
151 lines (138 loc) · 5.27 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
<html>
<head>
<meta charset="utf-8" />
<title>Quinn Freedman · Generative Art Experements</title>
<!-- <script type="text/javscript" src="https://github.com/gorhill/Javascript-Voronoi/blob/41a3cae6178385836187fdacd760b6abc96cc6d9/rhill-voronoi-core.min.js"></script> -->
<script src="lib/voronoi.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/seedrandom/3.0.1/seedrandom.min.js"></script>
<script>Math.seedrandom || document.write('<script src="lib/seedrandom.js">\x3C/script>')</script>
<!-- <script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/836/simplex-noise.min.js"></script> -->
<script src="lib/simplex-noise.min.js"></script>
<script src="src/numbers.js"></script>
<script src="src/util.js"></script>
<script src="src/webgl_helpers.js"></script>
<script>
const MAX_NUMBER = 40
</script>
<script>
for (let i = 1; i <= MAX_NUMBER; i++) {
let name = numberName(i)
document.write(`<script src="src/${name}.js"></script` + ">")
}
</script>
<style type="text/css">
body {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
font-family: Roboto, Arial, Helvetica, sans-serif;
margin: 0;
}
.container {
display: flex;
align-items: stretch;
justify-content: center;
flex-direction: row;
width: 100%;
}
.container .nav {
flex: 1;
cursor: pointer;
}
.container .nav:first-child:hover {
background-image: linear-gradient(to left, #00000000, #00000000, #00000050);
}
.container .nav:last-child:hover {
background-image: linear-gradient(to right, #00000000, #00000000, #00000050);
}
#title {
font-size: 2em;
}
#canvas-container {
margin-top: 8px;
}
.source {
font-family: Roboto, Arial, Helvetica, sans-serif;
position: fixed;
bottom: 4;
left: 4;
}
canvas {
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<div id="nav_left" class="nav"></div>
<div id="canvas-container">
<canvas id="canvas"></canvas>
</div>
<div id="nav_right" class="nav"></div>
</div>
<h1 id="title"></h1>
<a class="source" href="https://github.com/QuinnFreedman/doodles">source</a>
<script>
const params = new URL(document.location).searchParams
let n = params.get("n") || numberName(MAX_NUMBER)
const seed = params.get("seed")
const makeRng = () =>
seed
? new RNG(parseInt(seed), true)
: new RNG(Math.floor(Math.random() *
Number.MAX_SAFE_INTEGER), true)
let rng = makeRng()
console.log(n)
console.log("seed:", rng.seed)
document.getElementById("title").innerText = n
let deInit = window[n](rng)
document.querySelector("#canvas-container").addEventListener("click", restart_page)
document.querySelector("#nav_left").addEventListener("click", moveLeft)
document.querySelector("#nav_right").addEventListener("click", moveRight)
function restart_page() {
deInit && deInit()
rng = makeRng()
console.log("seed:", rng.seed)
deInit = window[n](rng)
}
function go_to(index) {
n = numberName(index)
deInit && deInit()
rng = makeRng()
console.log(n)
console.log("seed:", rng.seed)
deInit = window[n](rng)
document.getElementById("title").innerText = n
}
function moveLeft() {
let index = parseNumberName(n)
if (index > 1) {
go_to(index - 1)
}
}
function moveRight() {
let index = parseNumberName(n)
if (index >= 0 && index < MAX_NUMBER) {
go_to(index + 1)
}
}
let keys = new Map()
document.addEventListener("keyup", e => {
keys.set(e.key, false)
})
document.addEventListener("keydown", e => {
let key = e.key
if (keys.get(key)) return
keys.set(key, true)
if (key === "ArrowLeft") {
moveLeft()
} else if (key === "ArrowRight") {
moveRight()
} else if (key === "Enter" || key == " ") {
restart_page()
}
})
</script>
</body>
</html>