-
Notifications
You must be signed in to change notification settings - Fork 13
/
nimbea.lua
437 lines (381 loc) · 9.63 KB
/
nimbea.lua
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
-- Nimbea (nc01-drone)
-- @jaggednz
--
-- World 1:
-- first you will try to control,
-- then to predict
-- finally you will understand
--
-- World 2:
-- faced with the mountain rain
--
-- World 3:
-- the paradox of
-- manipulating chaos
--
-- E1 volume
-- E2 brightness
-- E3 density
-- K2 evolve
-- K3 change worlds
debug_msg = false
-- My sincerest apologies, all the code below is a messy hack
-- planetary.lua is a far better example to follow... ;)
-- black mesa
function world_one()
screen.level(15)
reverse_node_idx = #scape.nodes
screen.move(0,scape.nodes[1] or 0)
for p = 1,#scape.nodes do
offset = ((32-#scape.nodes)*4)-(frame%4)
screen.line(p*4+offset or 0,scape.nodes[p] or 0)
end
screen.stroke()
end
hills = { 27,29,47,43,44,34,56,49,54,63 }
function draw_temple()
screen.aa(1)
screen.level(1)
screen.move(0,64)
screen.line(0,20)
screen.line_rel(10,-2)
screen.line_rel(20,-4)
screen.line_rel(10,5)
screen.line_rel(20,5)
screen.line_rel(10,5)
screen.line_rel(20,15)
screen.line_rel(10,3)
screen.line_rel(20,4)
screen.line_rel(10,5)
screen.line_rel(20,-2)
screen.line_rel(10,5)
screen.line_rel(20,15)
screen.line_rel(10,-5)
screen.line_rel(20,-2)
screen.line(64,128)
screen.fill()
screen.level(0)
screen.move(70,46)
screen.line(70,30)
screen.line(80,31)
screen.line(80,47)
screen.fill()
screen.level(0)
screen.move(84,46)
screen.line(84,31)
screen.line(92,32)
screen.line(92,47)
screen.fill()
screen.level(0)
screen.move(64,29)
screen.line(64,32)
screen.stroke()
screen.level(2)
screen.curve(64,32, 72,28, 82,16)
screen.stroke()
screen.level(3)
screen.move(82,16)
screen.curve(82,16, 88,28, 96,34)
screen.line(96,31)
screen.stroke()
screen.level(0)
screen.move(59,49)
screen.line(59,52)
screen.stroke()
screen.move(59,52)
screen.curve(59,52, 72,48, 82,36)
screen.curve(82,36, 88,48, 101,54)
screen.fill()
screen.level(2)
screen.move(82,36)
screen.curve(82,36, 88,48, 101,54)
screen.stroke()
screen.level(0)
screen.move(101,54)
screen.line(101,51)
screen.stroke()
screen.move(63,64)
screen.line(63,52)
screen.line(97,54)
screen.line(97,64)
screen.fill()
screen.move(0,64)
screen.line(0,40)
for p = 1,9 do
screen.line(p*6,hills[p])
end
screen.line(60,64)
screen.fill()
end
-- dancing in the puddles
function world_two()
draw_temple()
screen.level(1)
for p = 1,#scape.nodes do
rain_falls = (scape.nodes[p] or 0) * math.random()
rain_falls_down = rain_falls+(32*math.random())
screen.level(1)
screen.move(p*4,rain_falls)
screen.line(p*4+2,rain_falls_down)
screen.stroke()
end
end
--[[
var rotateZ3D = function(theta) {
var sin_t = sin(theta);
var cos_t = cos(theta);
for (var n = 0; n < nodes.length; n++) {
var node = nodes[n];
var x = node[0];
var y = node[1];
node[0] = x * cos_t - y * sin_t;
node[1] = y * cos_t + x * sin_t;
}
};
]]--
function rotateZ(nodes,theta)
sin_t = math.sin(theta)
cos_t = math.cos(theta)
for n = 1,#nodes do
x = nodes[n].x
y = nodes[n].y
nodes[n].x = x * cos_t - y * sin_t;
nodes[n].y = y * cos_t + x * sin_t;
end
return nodes
end
incal_top = { {x=-16,y= 16},{x=-16,y=-16},{x= 16,y=-16},{x= 16,y= 16} }
incal_bottom = { {x=-16,y= 16},{x=-16,y=-16},{x= 16,y=-16},{x= 16,y= 16} }
-- rain drops dancing around the rotating incal ...
function world_three()
rotateZ(incal_top,0.03)
rotateZ(incal_bottom,-0.031)
for n = 1,4 do
screen.level(10+(incal_bottom[n].y//4))
screen.move(64,59)
screen.line(incal_bottom[n].x+64,(incal_bottom[n].y/4)+34)
screen.stroke()
end
screen.move(incal_bottom[4].x+64,(incal_bottom[4].y/4)+34)
for n = 1,4 do
screen.line(incal_bottom[n].x+64,(incal_bottom[n].y/4)+34)
end
screen.fill()
screen.level(0)
screen.move(incal_top[4].x+64,(incal_top[4].y/4)+30)
for n = 1,4 do
screen.line(incal_top[n].x+64,(incal_top[n].y/4)+30)
end
screen.fill()
screen.level(10)
screen.move(incal_top[4].x+64,(incal_top[4].y/4)+30)
for n = 1,4 do
screen.line(incal_top[n].x+64,(incal_top[n].y/4)+30)
end
screen.stroke()
for n = 1,4 do
screen.level(10+(incal_top[n].y//4))
screen.move(64,5)
screen.line(incal_top[n].x+64,(incal_top[n].y/4)+30)
screen.stroke()
end
end
worlds = {
{
title = '1',
file = 'dd.wav',
length= 136,
draw = world_one
},
{
title = '2',
file = 'bc.wav',
length= 166,
draw = world_two
},
{
title = '3',
file = 'eb.wav',
length= 128, --Actually 337
draw = world_three
}
}
world = 1
glitch = false
t = 1 --preload time forward, many movements move slowly at the start
title_fade = 15
params_fade = 0
volume = 60
brightness=48
density=100
scape = {
nodes = {},
max_nodes = 32,
offset = 0
}
-- OOP voices
sc_voices = {
number = 1,
channel = 1
}
function sc_voices:enable()
end
function sc_voices:init()
end
function sc_voices:set_buffer_ch(ch)
end
movements = {
function(t) return t*((t>>3|t>>12)*25+(t*4)) end,
function(t) return t//5|t*2&t//20>>1|45*t*-t//666|t//12|t//666>>2 end,
function(t) return t*((t>>9|t>>13)&25&t>>6) end,
function(t) return ((t>>3|t>>12)*25+(t*4)) end
}
function scape.add_node(node)
table.insert(scape.nodes,node)
-- remove oldest nodes
while #scape.nodes > scape.max_nodes do table.remove(scape.nodes,1) end
end
current_movement = 1
current_buffer = 1
voices = 6
current_voice = 1
voice_rate = { 1,1,1,1,1.0,1.0 }
voice_panning = { 0.25, 0.5, -0.5, -0.25,0.75,-0.75 }
voice_pan_rate = { 0.25 , 2, 2, 0.25, 1.5, 1.5 }
voice_lpf_cf = { }
voice_filter_rate = { 0.25 , 2, 2, 0.25, 1.5, 1.5 }
function load_world_buffer()
-- dd.wav ~ 136sec - default
-- bc.wav ~ 166sec - rain
-- eb.wav ~ 337sec - singing start ~ 240sec
file = _path.code .. "nc01-drone/lib/" .. worlds[world].file
print("opening world of ".. file)
softcut.buffer_read_mono(file,0,0,-1,1,current_buffer)
end
function init()
math.randomseed(os.time()) -- and the world was born, a rain drops dancing around wheels within wheels ...
load_world_buffer()
for v = 1,voices do
softcut.buffer(v,current_buffer)
softcut.loop(v,1)
softcut.loop_start(v,0)
softcut.loop_end(v,2)
--softcut.loop_end(v,3)
softcut.position(v,1)
softcut.fade_time(v,1.2)
softcut.level(v,0.0) -- start quiet!
softcut.level_slew_time(v,40) -- move slowly
softcut.pan(v,voice_panning[v])
softcut.pan_slew_time(v,voice_pan_rate[v])
softcut.rate(v, voice_rate[v] - ((v-1)/500)) --subtle variation in the playback rate per voice TODO add LFO?
softcut.play(v,1)
end
print("approaching...")
beat = metro.init(world_update, 0.25,-1)
beat:start()
end
frame=0
function world_update()
if frame%4==0 then shift() end
redraw()
frame=frame+1
end
function shift()
if frame%(61-brightness)==0 then t = t+brightness end
new_pos = (movements[current_movement](t) % (worlds[world].length * 10 ))/10 --((t>>3|t>>6)*25+(t*4))
softcut.buffer(current_voice,current_buffer)
softcut.position(current_voice,new_pos)
softcut.level(current_voice,volume/100) -- fade in
--Flip panning occasionally
if (t%7 == 1) then
glitch=true
voice_panning[current_voice] = voice_panning[current_voice] * -1
if debug_msg then print("Pan flip "..current_voice) end
end
vpan = (density/100) * (voice_panning[current_voice]*math.random())
softcut.pan(current_voice,vpan)
if debug_msg then print("t=" .. t .. " Assigning voice".. current_voice .." to position "..new_pos .. " panning " .. vpan) end
softcut.enable(current_voice,1)
scape.add_node(new_pos//4)
current_voice = current_voice + 1
if current_voice > voices then current_voice = 1 end
end
function enc(n,d)
if n == 1 then
-- E1 volume
volume = util.clamp(volume + d,0,100)
end
if n == 2 then
-- E2 brightness
brightness = util.clamp(brightness + d,1,60)
end
if n == 3 then
-- E3 density
density = util.clamp(density + d,0,100)
end
params_fade = 15
end
function key(n,z)
if (n==2 and z==1) then
-- K2 evolve
t = t + (2048*math.random())//10
current_movement = current_movement+1
if current_movement > #movements then current_movement = 1 end
print('evolving ...'..current_movement)
end
if (n==3 and z==1) then
-- K3 change worlds
current_buffer = current_buffer == 1 and 2 or 1
if debug_msg then print("buffer switched to " .. current_buffer) end
softcut.buffer_clear_channel(current_buffer)
if (world == 3) then
world = 1
else
world = world+1
end
title_fade = 15 -- Show the title fade
load_world_buffer()
end
end
function glitchDraw()
screen.level(3)
screen.font_face(1)
screen.font_size(50)
screen.text_center(""..world)
screen.move(64,50)
screen.level(title_fade)
screen.font_face(2)
screen.font_size(50)
screen.text_center(""..world)
glitch=false
end
function redraw()
screen.clear()
screen.aa(1)
worlds[world].draw()
if (params_fade>0) then
screen.level(params_fade)
screen.font_face(1)
screen.font_size(8)
screen.move(0,9)
screen.text("Vol. "..volume)
screen.move(0,16)
screen.text("Bri. ".. brightness)
screen.move(0,24)
screen.text("Den. "..density)
params_fade = params_fade -1
end
screen.move(64,50)
if (title_fade>0) then
if glitch == true then
glitchDraw()
else
screen.level(title_fade)
screen.font_face(5)
screen.font_size(50)
screen.text_center(""..world)
title_fade = title_fade-1
end
end
screen.update()
end