local ui = require("ui") -- No components: a canvas has one gesture and every pixel is content, so the app takes -- the touch callbacks raw. It wants the firmware's noise threshold and no gesture slop -- -- a three pixel stroke is a stroke, not a mis-tap. local theme = ui.theme local CLEAR = {x = 0, y = 0, w = 64, h = 28} local BRUSH = 2 local lastX, lastY local function inClear(x, y) return x < CLEAR.w and y < CLEAR.h end local function clear() gui.clear(theme.bg) gui.roundRect(CLEAR.x, CLEAR.y, CLEAR.w, CLEAR.h, theme.radius, theme.bg, theme.face[1], theme.face[2], theme.fg) gui.drawText("clear", 14, 10, theme.fg) end function init() clear() log.info("paint ready") end function on_touch_down(x, y) if inClear(x, y) then lastX = nil return clear() end lastX, lastY = x, y gui.fillCircle(x, y, BRUSH, theme.accent) end -- Strokes are joined with a line because the poll rate, not the finger, decides the gap: -- a fast swipe reports points tens of pixels apart and dots alone would look dotted. function on_touch_move(x, y) if not lastX then return end gui.drawLine(lastX, lastY, x, y, theme.accent) gui.fillCircle(x, y, BRUSH, theme.accent) lastX, lastY = x, y end function on_touch_up() lastX = nil end