dronecaster.lua
-- DRONECASTER
--
-- k1: exit e1: amp
--
-- e2: hz e3: drone
-- k2: alt k3: cast
--
engine.name = 'Engine_Dronecaster'
drones = {'Sine', 'Eno', 'Belong', 'Hecker', 'Gristle', 'Starlids', 'GY!BE', 'V/Vm', 'Canada'}
function init()
-- ui
altKey = false
castKey = false
-- time
seconds = 0
counter = metro.init()
counter.time = 1
counter.count = -1
counter.event = theSandsOfTime
counter.play = 0
-- draw
screen.aa(0)
screenO = 0
screenL = 5
screenM = 10
screenH = 15
screen.level(screenH)
screen.font_face(0)
screen.font_size(8)
-- animation
frame = 1
driftMaxX = 5
driftMaxY = 3
joeHomeX = 25
joeHomeY = 25
bethHomeX = 20
bethHomeY = 30
alexHomeX = 32
alexHomeY = 29
-- params
params:add_control("amp","amp",controlspec.new(0,1,'amp',0,0.5,'amp'))
params:set_action("amp", function(x) updateAmp(x) end)
params:add_control("hz","hz",controlspec.new(0,20000,'lin',0,440,'hz'))
params:set_action("hz", function(x) updateHz(x) end)
params:add_control("drone","drone",controlspec.new(1,9,'lin',0,1,'drone'))
params:set_action("drone", function(x) updateType(x) end)
counter:start()
counter.play = 1
end
function theSandsOfTime(c)
seconds = c
frame = frame + 1
redraw()
end
function count()
units = units+1
ms = units / 100
seconds = ms % 60
redraw()
end
function redraw()
screen.clear()
drawLandscape()
drawBirds()
drawClock()
drawPlayStop()
drawTopMenu()
screen.update()
end
function updateHz(x)
engine.hz(x)
end
function updateAmp(x)
-- engine.amp(x)
end
function updateType(x)
end
-- enc & keys - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function enc(n,d)
-- amp
if n == 1 and altKey then
params:delta("amp", d)
elseif n == 1 then
params:delta("amp", d * .1)
end
-- hz
if n == 2 and altKey then
params:delta("hz", d)
elseif n == 2 then
params:delta("hz", d * .01)
end
-- drone
if n == 3 then
params:delta("drone", d)
end
redraw()
end
function key(n,z)
-- k2 alt
if n == 2 and z == 1 then
altKey = true
elseif n == 2 and z == 0 then
altKey = false
end
-- k3 start/stop
if n == 3 and z == 1 then
if counter.play == 1 then
counter:stop()
counter.play = 0
frame = 1
else
counter:start()
counter.play = 1
units = 0
end
end
redraw()
end
-- utils - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function round(num, places)
if places and places > 0 then
local mult = 10 ^ places
return math.floor(num * mult + 0.5) / mult
end
return math.floor(num + 0.5)
end
-- draws - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function drawBirds()
screen.level(screenL)
birdFrame = frame % 3
-- drifting works but need to implement boundaries
-- driftX = math.random(0, 1)
-- driftY = math.random(0, 1)
-- operator = math.random(0, 1)
-- if operator == 0 then
-- driftX = driftX * -1
-- driftY = driftY * -1
-- end
-- joeHomeX = joeHomeX + driftX
-- joeHomeY = joeHomeY + driftY
-- bethHomeX = bethHomeX + driftX
-- bethHomeY = bethHomeY + driftY
-- alexHomeX = alexHomeX + driftX
-- alexHomeY = alexHomeY + driftY
if birdFrame == 0 then
-- joe
screen.move(joeHomeX, joeHomeY)
screen.line_rel(2, 2)
screen.move(joeHomeX, joeHomeY)
screen.line_rel(-2, 2)
-- beth
screen.move(bethHomeX, bethHomeY)
screen.line_rel(2, -2)
screen.move(bethHomeX, bethHomeY)
screen.line_rel(-2, -2)
-- alex
screen.move(alexHomeX, alexHomeY)
screen.line_rel(2, 1)
screen.move(alexHomeX, alexHomeY)
screen.line_rel(-2, 1)
end
if birdFrame == 1 then
-- joe
screen.move(joeHomeX, joeHomeY)
screen.line_rel(2, 1)
screen.move(joeHomeX, joeHomeY)
screen.line_rel(-2, 1)
-- beth
screen.move(bethHomeX, bethHomeY)
screen.line_rel(2, 2)
screen.move(bethHomeX, bethHomeY)
screen.line_rel(-2, 2)
-- alex
screen.move(alexHomeX, alexHomeY)
screen.line_rel(2, -2)
screen.move(alexHomeX, alexHomeY)
screen.line_rel(-2, -2)
end
if birdFrame == 2 then
-- joe
screen.move(joeHomeX, joeHomeY)
screen.line_rel(2, -2)
screen.move(joeHomeX, joeHomeY)
screen.line_rel(-2, -2)
-- beth
screen.move(bethHomeX, bethHomeY)
screen.line_rel(2, 1)
screen.move(bethHomeX, bethHomeY)
screen.line_rel(-2, 1)
-- alex
screen.move(alexHomeX, alexHomeY)
screen.line_rel(2, 2)
screen.move(alexHomeX, alexHomeY)
screen.line_rel(-2, 2)
end
end
function drawLandscape()
screen.level(screenL)
-- antenna sides
screen.move(62, 52)
screen.line(66, 20)
screen.move(70, 53)
screen.line(66, 20)
-- antenna horizontals
screen.move(64, 34)
screen.line_rel(3, 0)
screen.move(64, 39)
screen.line_rel(3, 0)
screen.move(64, 45)
screen.line_rel(3, 0)
-- antenna supports
screen.move(62,52)
screen.line(70,44)
screen.move(70,52)
screen.line(62,44)
screen.move(70,44)
screen.line(63,37)
-- antenna details
screen.move(65, 19)
screen.line_rel(2, 0)
screen.move(65, 17)
screen.line_rel(1, 0)
screen.move(62, 30)
screen.line_rel(2,0)
screen.move(67, 28)
screen.line_rel(2, 0)
screen.move(62, 27)
screen.line_rel(1, 2)
screen.move(62, 25)
screen.line_rel(1, 1)
screen.move(69, 25)
screen.line_rel(1, 2)
screen.move(69, 23)
screen.line_rel(1, 1)
-- distant horizon
screen.move(0,48)
screen.line_rel(60, 0)
screen.move(72,48)
screen.line_rel(50, 0)
-- second horizon
screen.move(1, 50)
screen.line_rel(1, 0)
screen.move(4, 50)
screen.line_rel(40, 0)
screen.move(46, 50)
screen.line_rel(9, 0)
screen.move(57, 50)
screen.line_rel(1, 0)
screen.move(74, 50)
screen.line_rel(40, 0)
screen.move(116, 50)
screen.line_rel(2, 0)
-- third horizon
screen.move(5, 55)
screen.line_rel(3, 0)
screen.move(10, 55)
screen.line_rel(40, 0)
screen.move(55, 55)
screen.line_rel(20, 0)
screen.move(80, 55)
screen.line_rel(41, 0)
screen.move(80, 55)
-- closest horizon
screen.move(39, 62)
screen.line_rel(71, 0)
end
function drawTopMenu()
screen.level(screenL)
if altKey then
for i=11,0,-1 do
screen.move(0, i)
screen.line_rel(40,0)
screen.move(44,i)
screen.line_rel(40,0)
end
end
screen.move(0,12)
screen.line_rel(40,0)
screen.move(44,12)
screen.line_rel(40,0)
screen.move(88,12)
screen.line_rel(40,0)
-- todo: understand why commenting out this breaks the landscape
screen.stroke()
screen.level(screenH)
screen.move(2,8)
screen.text(round(params:get("amp"),2) .. " amp")
screen.move(45,8)
screen.text(round(params:get("hz")) .. " hz")
screen.move(89,8)
screen.text(drones[round(params:get("drone"))])
end
function drawClock()
screen.level(screenL)
screen.move(2,64)
local display_time = util.s_to_hms (seconds)
screen.text(display_time)
end
function drawPlayStop()
screen.level(screenL)
if counter.play == 1 then
-- play
screen.move(33, 59)
screen.line(33, 64)
screen.move(34, 60)
screen.line(34, 63)
screen.move(35, 61)
screen.line(35, 62)
else
-- stop
screen.move(33, 59)
screen.line(33, 64)
screen.move(34, 59)
screen.line(34, 64)
screen.move(35, 59)
screen.line(35, 64)
screen.move(36, 59)
screen.line(36, 64)
end
end