forked from monome-community/nc01-drone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
planetary.lua
executable file
·186 lines (155 loc) · 4.02 KB
/
planetary.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
-- planetary (nc01-drone)
-- @infovore
--
-- with apologies
-- to michel gondry
--
-- E1 volume
-- E2 brightness
-- E3 density
-- K2 evolve
-- K3 change worlds
local utils = include('lib/planetary/utils')
local graphics = include('lib/planetary/graphics')
sc = softcut -- typing shortcut
-- graphics things
horizon_height = 28
world_stars = {}
-- sound things
current_world = 1
level = {1,0,0}
pulse_duration = 2
brightnesses = {1,1,1}
probs = {0.2,0.2,0.2} -- probabilities per world
start_points = {1,181,30}
loop_points = start_points
buffer_indexes = {1,1,2}
events = {} -- ie, things in the landscape.
function init_all_events()
for world=1,3 do
events[world] = {}
init_world_events(world)
end
end
function init_world_events(world)
for step = 1,16 do
event = {}
event.x = (step-1) * 16
event.y = utils.random_between(horizon_height+5,64)
event.seed = math.random()
events[world][step] = event
end
end
function init()
init_all_events()
graphics.init_all_stars()
file1 = _path.code .. "nc01-drone/lib/dd.wav"
file2 = _path.code .. "nc01-drone/lib/bc.wav"
file3 = _path.code .. "nc01-drone/lib/eb.wav"
sc.buffer_read_mono(file1,0,0,-1,1,1)
sc.buffer_read_mono(file2,0,180,-1,1,1)
sc.buffer_read_mono(file3,0,0,-1,1,2)
for i=1,3 do
sc.enable(i,1)
sc.buffer(i,buffer_indexes[i])
sc.level(i,level[i])
sc.loop(i,0)
sc.rate(i,1.0)
sc.play(i,0)
sc.post_filter_dry(i,0)
sc.post_filter_lp(i,1)
sc.post_filter_hp(i,0)
sc.post_filter_bp(i,0)
sc.post_filter_br(i,0)
sc.post_filter_rq(i,0.6)
freq = util.linexp(0, 1, 60, 12000, brightnesses[i])
sc.post_filter_fc(i,freq)
sc.loop_start(i,start_points[i])
sc.loop_end(i,start_points[i]+pulse_duration)
sc.position(i,start_points[i])
end
animation_clock = metro.init(tick, (1.0/60), -1)
animation_clock:start()
world1_clock = metro.init(world1_tick, (1.0/40), -1)
world1_clock:start()
world2_clock = metro.init(world2_tick, (1.0/30), -1)
world2_clock:start()
world3_clock = metro.init(world3_tick, (1.0/20), -1)
world3_clock:start()
end
function tick(stage)
redraw(stage)
end
function world1_tick(stage)
world_tick(1)
end
function world2_tick(stage)
world_tick(2)
end
function world3_tick(stage)
world_tick(3)
end
function world_tick(world)
world_events = events[world]
utils.dump(world_events)
for i = 1,#world_events do
e = world_events[i]
e.x = e.x - util.linlin(horizon_height+5,64,0.5,1.5,e.y)
if e.x < 0 then
e.x = 128
if e.seed < probs[world] then
sc.position(world, loop_points[world])
sc.play(world,1)
end
end
end
end
function enc(n,d)
if n==1 then
level[current_world] = util.clamp(level[current_world] + d/100,0,1)
sc.level(current_world, level[current_world])
elseif n==2 then
brightnesses[current_world] = util.clamp(brightnesses[current_world] + d/100,0,1)
freq = util.linexp(0, 1, 60, 6000, brightnesses[current_world])
sc.post_filter_fc(current_world,freq)
elseif n==3 then
-- adjust world probablity
prob = probs[current_world] + d/100.0
probs[current_world] = util.clamp(prob,0,0.9)
end
end
function key(n,z)
if n==3 and z==1 then
current_world = current_world % 3 + 1
elseif n==2 and z==1 then
init_world_events(current_world)
pick_new_loop(current_world)
end
end
function pick_new_loop(world)
if world == 1 then
new_start = utils.random_between(1,60)
elseif world == 2 then
new_start = utils.random_between(180,300)
else
new_start = utils.random_between(20,400)
end
loop_points[world] = new_start
sc.loop_start(world, new_start)
sc.loop_end(world, new_start+pulse_duration)
sc.position(world, new_start)
end
function redraw(stage)
screen.clear()
screen.line_width(1)
screen.line_cap("butt")
screen.level(16)
screen.move(0,5)
screen.aa(1)
screen.text(current_world)
graphics.draw_stars()
graphics.draw_sun(current_world)
graphics.draw_horizon(current_world)
graphics.draw_landscape(current_world)
screen.update()
end