-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathnornsilerplate.lua
71 lines (61 loc) · 2.82 KB
/
nornsilerplate.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
-- HTTPS://NOR.THE-RN.INFO
-- NORNSILERPLATE
-- >> k1: exit
-- >> k2:
-- >> k3:
-- >> e1:
-- >> e2:
-- >> e3:
function init() ------------------------------ init() is automatically called by norns
message = "NORNSILERPLATE" ----------------- set our initial message
screen_dirty = true ------------------------ ensure we only redraw when something changes
redraw_clock_id = clock.run(redraw_clock) -- create a "redraw_clock" and note the id
end
function enc(e, d) --------------- enc() is automatically called by norns
if e == 1 then turn(e, d) end -- turn encoder 1
if e == 2 then turn(e, d) end -- turn encoder 2
if e == 3 then turn(e, d) end -- turn encoder 3
screen_dirty = true ------------ something changed
end
function turn(e, d) ----------------------------- an encoder has turned
message = "encoder " .. e .. ", delta " .. d -- build a message
end
function key(k, z) ------------------ key() is automatically called by norns
if z == 0 then return end --------- do nothing when you release a key
if k == 2 then press_down(2) end -- but press_down(2)
if k == 3 then press_down(3) end -- and press_down(3)
screen_dirty = true --------------- something changed
end
function press_down(i) ---------- a key has been pressed
message = "press down " .. i -- build a message
end
function redraw_clock() ----- a clock that draws space
while true do ------------- "while true do" means "do this forever"
clock.sleep(1/15) ------- pause for a fifteenth of a second (aka 15fps)
if screen_dirty then ---- only if something changed
redraw() -------------- redraw space
screen_dirty = false -- and everything is clean again
end
end
end
function redraw() -------------- redraw() is automatically called by norns
screen.clear() --------------- clear space
screen.aa(1) ----------------- enable anti-aliasing
screen.font_face(1) ---------- set the font face to "04B_03"
screen.font_size(8) ---------- set the size to 8
screen.level(15) ------------- max
screen.move(64, 32) ---------- move the pointer to x = 64, y = 32
screen.text_center(message) -- center our message at (64, 32)
screen.pixel(0, 0) ----------- make a pixel at the north-western most terminus
screen.pixel(127, 0) --------- and at the north-eastern
screen.pixel(127, 63) -------- and at the south-eastern
screen.pixel(0, 63) ---------- and at the south-western
screen.fill() ---------------- fill the termini and message at once
screen.update() -------------- update space
end
function r() ----------------------------- execute r() in the repl to quickly rerun this script
norns.script.load(norns.state.script) -- https://github.com/monome/norns/blob/main/lua/core/state.lua
end
function cleanup() --------------- cleanup() is automatically called on script close
clock.cancel(redraw_clock_id) -- melt our clock vie the id we noted
end