-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar.js
More file actions
183 lines (167 loc) · 3.26 KB
/
grammar.js
File metadata and controls
183 lines (167 loc) · 3.26 KB
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
// NOTE: this files assumes the lambda.min.js library is in the global scope
// you should disable everything but syntax checks for this file
module.exports = n => {
const customRng = (...fs) => lambda(x => {
// e.g. this is essentially a rotating scale
let i = 0
const seq = evaluate(x, pipe(...fs))
return rng(() => seq[i++ % seq.length])
})
const obj = o => lambda(x => {
const result = {}
for (const k in o) {
result[k] = evaluate(x, o[k])
}
return result
})
const vec3 = n => val(times(3, n))
const consonant = pick(...'bdfgklmnprstwxyz')
const vowel = pick(...'aeiou')
const syllable = u => pipe(
set.upperCase(u),
join(
pipe(
consonant,
when(get.upperCase, upperCase)
),
vowel
)
)
const word = length => join(
pipe(
times(length),
syllable(eq(0))
)
)
const name = pick(
word(pick(2, 3, 4)),
join(
word(pick(1, 2)),
'-',
word(pick(1, 2))
)
)
const ruler = pick(
'Eater',
'Consumer',
'Pillager',
'Ravager',
'Destroyer',
'Corrupter',
'Tainter',
'Torturer',
'Executioner',
'Inquisitor',
'Enslaver',
'Master',
'Tyrant'
)
const domain = pick(
'Dreams',
'the Void',
'Dimensions',
'the Unseen',
'Shadows',
'the Deep',
'Death'
)
const title = join(
ruler,
' of ',
domain
)
const iris = pipe(
times(floor(uniform(2, 8))),
set.primitive('triangles'),
set.depth(0),
set.speed(uniform(1/240, 1/60), mul(pick(1, -1))),
set.color(vec3(random)),
set.alpha(1),
set.vertex(
set.offset(
uniform(0, 0.4)
),
set.count(
uniform(5, 100),
floor(it),
mul(3)
),
times(get.count),
val(
fork(
div(get.count),
pipe(
get.radius,
minus(uniform(0, mul(0.2))),
plus(uniform(0, 0.3)),
plus(get.offset)
)
)
)
)
)
const pupil = pipe(
set.corners(40),
set.count(5),
set.primitive('triangle fan'),
set.speed(0),
set.color(vec3(0)),
times(get.count),
set.indexR(it, plus(1)),
set.index(negate(it), plus(get.count)),
set.depth(
get.indexR,
div(get.count)
),
set.alpha(
get.indexR,
div(get.count)
),
set.radius(
get.radius,
plus(prod(mul(0.2), get.index))
),
set.vertex(fork(
val([0, 0]),
pipe(
times(get.corners(plus(1))),
val(fork(
div(get.corners),
get.radius
))
)
))
)
const shape = obj({
color: get.color,
alpha: get.alpha,
depth: get.depth,
vertex: get.vertex,
speed: get.speed,
primitive: get.primitive
})
const scene = obj({
name: get.name,
title: get.title,
color: get.color,
shapes: get.shapes,
radius: get.radius
})
const eye = pipe(
set.name(n ? [n] : name),
seed(get.name),
set.title(title),
set.color(vec3(uniform(0.1, 0.2))),
set.radius(uniform(0.05, 0.2)),
customRng(
times(floor(uniform(3, 40))),
random
),
set.shapes(
fork(iris, pupil),
shape
),
scene
)
return evaluate(root, eye)
}