info = { type = "image", title = "Tin robot", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A retro tin robot with a ticking chest clock", api = 33, } local ltr = ({ sk = { ["Tin colour"] = "Farba plechu", ["Arm swing"] = "Mávanie rukou", ["Clock speed"] = "Rýchlosť hodín", ["Steam"] = "Para" }, cs = { ["Tin colour"] = "Barva plechu", ["Arm swing"] = "Mávání rukou", ["Clock speed"] = "Rychlost hodin", ["Steam"] = "Pára" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "tin", label = LT("Tin colour"), type = "color", default = "#D9503A" }, { key = "swing", label = LT("Arm swing"), type = "int", min = 0, max = 5, default = 3 }, { key = "tick", label = LT("Clock speed"), type = "int", min = 1, max = 5, default = 3 }, { key = "steam", label = LT("Steam"), type = "bool", default = true }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, cos, sqrt = math.floor, math.sin, math.cos, math.sqrt local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local TAU = 6.2831853 local WALL, HALO1, HALO2 = { 14, 30, 70 }, { 22, 46, 96 }, { 32, 62, 120 } local FLOOR, FLOOR_L, SHADOW = { 38, 76, 130 }, { 70, 116, 172 }, { 22, 44, 88 } local BRASS, BRASS_D = { 244, 196, 66 }, { 168, 120, 36 } local CREAM, INK = { 246, 238, 212 }, { 22, 28, 56 } local PLATE, EYE, PUPIL = { 12, 20, 44 }, { 120, 250, 255 }, { 10, 20, 44 } local GREY = { 150, 160, 184 } local B, BL, BD, BP = { 217, 80, 58 }, { 240, 142, 112 }, { 134, 48, 38 }, { 178, 64, 46 } local function c3(c) return c[1], c[2], c[3] end local function disc(cx, cy, r, R, G, Bl) for y = cy - floor(r), cy + floor(r) do local dy = y - cy local hw = floor(sqrt(r * r - dy * dy) + 0.5) rect(cx - hw, y, 2 * hw + 1, 1, R, G, Bl) end end local BG = nil local function build_bg() rect(0, 0, W, H, c3(WALL)) disc(32, 31, 25, c3(HALO1)) disc(32, 31, 18, c3(HALO2)) rect(0, 57, W, 7, c3(FLOOR)) rect(0, 57, W, 1, c3(FLOOR_L)) rect(19, 60, 13, 2, c3(SHADOW)); rect(34, 60, 13, 2, c3(SHADOW)) rect(32, 5, 1, 4, c3(GREY)) rect(38, 7, 3, 3, c3(BRASS_D)); rect(38, 7, 3, 1, c3(BRASS)) rect(23, 9, 19, 15, c3(B)) rect(22, 10, 21, 13, c3(B)) rect(23, 10, 19, 1, c3(BL)); rect(22, 11, 1, 11, c3(BL)) rect(42, 11, 1, 11, c3(BD)); rect(23, 23, 19, 1, c3(BD)) for _, x in ipairs({ 19, 43 }) do rect(x, 13, 3, 8, c3(BD)) rect(x, 14, 3, 6, c3(BRASS_D)) rect(x, 14, 2, 6, c3(BRASS)) end rect(28, 24, 9, 2, c3(INK)); rect(28, 24, 9, 1, c3(GREY)) rect(18, 26, 29, 26, c3(B)) rect(17, 27, 31, 24, c3(B)) rect(18, 26, 29, 1, c3(BL)); rect(17, 27, 1, 23, c3(BL)) rect(47, 27, 1, 23, c3(BD)); rect(18, 51, 29, 1, c3(BD)) rect(20, 28, 25, 22, c3(BP)) px(21, 29, c3(BRASS)); px(43, 29, c3(BRASS)); px(21, 48, c3(BRASS)); px(43, 48, c3(BRASS)) disc(32, 36, 7.4, c3(BRASS_D)) disc(32, 36, 6.4, c3(BRASS)) disc(32, 36, 5.4, c3(CREAM)) px(32, 32, c3(INK)); px(32, 40, c3(INK)); px(28, 36, c3(INK)); px(36, 36, c3(INK)) rect(14, 28, 5, 5, c3(BRASS_D)); rect(14, 28, 4, 4, c3(BRASS)) rect(46, 28, 5, 5, c3(BRASS_D)); rect(46, 28, 4, 4, c3(BRASS)) rect(23, 52, 6, 5, c3(BD)); rect(36, 52, 6, 5, c3(BD)) rect(23, 52, 2, 5, c3(B)); rect(36, 52, 2, 5, c3(B)) rect(21, 57, 9, 3, c3(BRASS_D)); rect(35, 57, 9, 3, c3(BRASS_D)) rect(21, 57, 9, 1, c3(BRASS)); rect(35, 57, 9, 1, c3(BRASS)) BG = gfx.snapshot(0, 0, W, H) end function on_settings() local c = cfg.tin or { r = 217, g = 80, b = 58 } B = { c.r, c.g, c.b } BL = { c.r + (255 - c.r) * 4 // 10, c.g + (255 - c.g) * 4 // 10, c.b + (255 - c.b) * 4 // 10 } BD = { c.r * 6 // 10, c.g * 6 // 10, c.b * 6 // 10 } BP = { c.r * 8 // 10, c.g * 8 // 10, c.b * 8 // 10 } BG = nil end local function sstep(x) if x <= 0 then return 0 elseif x >= 1 then return 1 end return x * x * (3 - 2 * x) end local function turn(f) local p = f % 480 return (sstep((p - 60) / 30) - sstep((p - 150) / 30)) - (sstep((p - 300) / 30) - sstep((p - 390) / 30)) end local LAMPC = { { 90, 255, 120 }, { 255, 200, 70 }, { 255, 96, 84 } } local LAMPD = { { 22, 70, 36 }, { 80, 58, 20 }, { 80, 28, 26 } } local function arm(jx, jy, th, side) local s, c = sin(th) * side, cos(th) local R, G, Bb = c3(BL) for i = 4, 15, 2 do rect(floor(jx + i * s + 0.5) - 1, floor(jy + i * c + 0.5) - 1, 3, 3, R, G, Bb) end local hx, hy = floor(jx + 17 * s + 0.5), floor(jy + 17 * c + 0.5) rect(hx - 2, hy - 1, 4, 4, c3(BRASS_D)) rect(hx - 2, hy - 1, 4, 2, c3(BRASS)) px(hx - 1, hy + 2, c3(WALL)); px(hx, hy + 2, c3(WALL)) end local function hand(a, len, R, G, Bb) local s, c = sin(a), cos(a) for i = 1, len do px(floor(32 + i * s + 0.5), floor(36 - i * c + 0.5), R, G, Bb) end end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local f = frame * STEP_HZ // FPS if cfg.steam ~= false then for i = 0, 2 do local a = ((f + i * 30) % 90) / 90 local sz = a > 0.45 and 3 or 2 blend_rect(floor(39 + 2.5 * sin(a * 5 + i * 2) + 0.5), floor(6 - 15 * a + 0.5), sz, sz, 236, 240, 250, 0.7 * (1 - a)) end end local on = (f // 20) % 2 == 0 if on then blend_rect(29, 0, 7, 7, 255, 70, 60, 0.30) rect(31, 1, 3, 3, 255, 96, 84) else rect(31, 1, 3, 3, 120, 36, 40) end local ea = (f // 25) % 2 == 0 rect(19, 15, 2, 2, ea and 90 or 24, ea and 255 or 70, ea and 120 or 36) rect(44, 15, 2, 2, ea and 80 or 255, ea and 58 or 200, ea and 20 or 70) local k = (f // 8) % 5 for i = 0, 2 do if k == i then px(29 + 3 * i, 10, 255, 232, 96) else px(29 + 3 * i, 10, c3(BD)) end end local T, Te = turn(f), turn(f + 12) local aT = T < 0 and -T or T local cx = 32 + floor(2.6 * T + (T < 0 and -0.5 or 0.5)) local pw = 15 - floor(2 * aT + 0.5) local sep = 3 - floor(aT + 0.5) rect(cx - pw // 2, 12, pw, 10, c3(PLATE)) local ey, eh = 13, 4 if (f + 37) % 150 < 4 then ey, eh = 15, 1 end local pxo = floor(Te + (Te < 0 and -0.5 or 0.5)) local ex = cx - sep - 3 rect(ex, ey, 4, eh, c3(EYE)) if eh > 1 then rect(ex + 1 + pxo, 14, 2, 2, c3(PUPIL)) end ex = cx + sep rect(ex, ey, 4, eh, c3(EYE)) if eh > 1 then rect(ex + 1 + pxo, 14, 2, 2, c3(PUPIL)) end local seg = f // 5 for j = 0, 4 do local h = 1 + (hash32(seg * 7 + j * 131) & 0x7FFF) % 3 rect(cx - 4 + 2 * j, 21 - h, 1, h, 200, 214, 236) end local ti = (f // 12) for i = 0, 2 do local lit = (ti + i) % 3 == 0 local c = lit and LAMPC[i + 1] or LAMPD[i + 1] rect(26 + 5 * i, 46, 3, 2, c[1], c[2], c[3]) end local sp = cfg.tick or 3 local aL = f * TAU / (STEP_HZ * 40 / sp) hand(aL / 12, 3, c3(INK)) hand(aL, 5, c3(INK)) px(32, 36, 255, 90, 70) local A = (cfg.swing or 3) * 0.11 local th = A * sin(f * TAU / 72) arm(16, 30, th, -1) arm(48, 30, -th, 1) end