I have a lot of neat little sketches that shouldn’t really have their own threads, so I will post them here, and you are all welcome to do the same 
Here’s one:
Etch N Sketch
local viewport = { width = 128, height = 64 }
local focus = { x = 0, y = 0, is_drawing = true }
-- Main
function init()
-- Render Style
screen.level(15)
screen.aa(0)
screen.line_width(1)
-- Center focus
focus.x = 0
focus.y = viewport.height-1
-- Render
erase()
end
function toggle_drawing()
if focus.is_drawing == true then
focus.is_drawing = false
else
focus.is_drawing = true
end
end
-- Interactions
function key(id,state)
if id == 2 and state == 1 then
erase()
elseif id == 3 and state == 1 then
toggle_drawing()
end
end
function enc(id,delta)
if id == 2 then
focus.x = clamp(focus.x + delta,0,viewport.width-1)
elseif id == 3 then
focus.y = clamp(focus.y - delta,0,viewport.height-1)
end
redraw()
end
-- Render
function erase()
screen.clear()
draw_focus()
screen.update()
end
function draw_focus()
if focus.is_drawing == true then
screen.pixel(focus.x,focus.y)
end
screen.fill()
end
function redraw()
draw_focus()
screen.update()
end
-- Utils
function clamp(val,min,max)
return val < min and min or val > max and max or val
end