info = { type = "image", title = "Tea and books", category = "other", author = "BRRRO", version = "1.0", license = "MIT", desc = "Cup of tea on a book stack by a desk lamp", api = 33, } local tr = ({ sk = { ["Lamp"] = "Lampa", ["Steam"] = "Para", ["Page turning"] = "Otáčanie strán" }, cs = { ["Lamp"] = "Lampa", ["Steam"] = "Pára", ["Page turning"] = "Otáčení stran" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "lamp", label = T("Lamp"), type = "bool", default = true }, { key = "steam", label = T("Steam"), type = "int", min = 0, max = 3, default = 2 }, { key = "pages", label = T("Page turning"), type = "bool", default = true }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, sin, cos = math.floor, math.sin, math.cos local W, H, FPS = gfx.W, gfx.H, gfx.FPS local WALL, CONE, CONE2 = { 52, 46, 48 }, { 64, 54, 50 }, { 80, 66, 54 } local TABLE, TABLE_L, TABLE_F = { 94, 68, 52 }, { 118, 86, 62 }, { 66, 46, 38 } local PAGE, PAGE_D, INK = { 238, 230, 212 }, { 212, 202, 182 }, { 160, 148, 130 } local STEAM = { 252, 244, 232 } local function c3(c) return c[1], c[2], c[3] end local function book(x, y, w, h, c, band, title) rect(x, y, w, h, c3(c)) rect(x + 2, y, 2, h, c3(band)); rect(x + w - 4, y, 2, h, c3(band)) rect(x + 7, y + h // 2, w - 15, 1, c3(title)) rect(x, y, w, 1, c[1] + 14, c[2] + 14, c[3] + 14) end local BG, BG_KEY = nil, nil local function build_bg(lamp) rect(0, 0, W, H, c3(WALL)) if lamp then for y = 32, 51 do local d = y - 32 rect(45 - floor(d * 1.1), y, 8 + floor(d * 2.2), 1, c3(CONE)) rect(46 - floor(d * 0.5), y, 6 + floor(d * 1.0), 1, c3(CONE2)) end end rect(0, 52, W, 4, c3(TABLE)); rect(0, 52, W, 1, c3(TABLE_L)); rect(0, 56, W, 8, c3(TABLE_F)) if lamp then rect(26, 53, 38, 2, c3(TABLE_L)) end book(2, 44, 32, 8, { 54, 100, 94 }, { 38, 76, 72 }, { 150, 190, 180 }) book(6, 37, 24, 7, { 64, 104, 146 }, { 46, 76, 112 }, { 160, 190, 220 }) book(5, 31, 22, 6, { 128, 62, 60 }, { 200, 164, 96 }, { 214, 176, 108 }) book(11, 26, 16, 5, { 146, 150, 118 }, { 110, 116, 88 }, { 190, 190, 160 }) rect(11, 25, 14, 1, 210, 200, 184) rect(13, 19, 10, 5, 234, 224, 206); rect(14, 24, 8, 1, 234, 224, 206) rect(21, 19, 2, 6, 190, 178, 158) rect(14, 18, 8, 1, 234, 224, 206); rect(14, 19, 8, 1, 154, 94, 46) px(13, 19, 234, 224, 206); px(22, 19, 234, 224, 206) rect(23, 20, 2, 1, 234, 224, 206); rect(24, 21, 1, 2, 234, 224, 206); rect(23, 23, 1, 1, 234, 224, 206) rect(35, 52, 20, 1, 96, 52, 52); rect(36, 45, 9, 7, c3(PAGE)); rect(46, 45, 8, 7, c3(PAGE)) rect(45, 45, 1, 7, c3(PAGE_D)); rect(36, 51, 18, 1, c3(PAGE_D)) for y = 46, 50, 2 do rect(37, y, 7, 1, c3(INK)); rect(47, y, 6, 1, c3(INK)) end rect(56, 50, 8, 2, 110, 98, 92); rect(57, 49, 6, 1, 110, 98, 92) rect(59, 36, 2, 13, 132, 118, 106) for k = 0, 7 do rect(60 - k, 36 - floor(k * 1.1), 2, 2, 132, 118, 106) end local ys = { { 47, 51 }, { 46, 52 }, { 45, 53 }, { 44, 54 }, { 43, 55 } } for i = 1, 5 do rect(ys[i][1], 25 + i, ys[i][2] - ys[i][1] + 1, 1, i == 1 and 222 or 190, i == 1 and 150 or 122, i == 1 and 84 or 68) end if lamp then rect(45, 31, 9, 1, 255, 232, 170) else rect(45, 31, 9, 1, 112, 104, 98) end BG = gfx.snapshot(0, 0, W, H) end local WISP = { { 0, 1, 1, 0, -1, -1, 0, 1, 1 }, { 0, -1, -1, 0, 1, 1, 0, -1, -1 } } local PERIOD = 5.2 local function draw_wisp(i, n, t) local u = ((t + (i - 1) * PERIOD / n) % PERIOD) / PERIOD local a = 0.85 * sin(3.14159 * u) ^ 1.1 if a < 0.03 then return end local shape = WISP[i % 2 + 1] local cx = 17.5 + (i - 2) * 1.8 + 2.2 * sin(6.2832 * (u * 1.1 + i * 0.31)) local top = 15.5 - u * 12 - 9 local x0 = floor(cx) local fx = cx - x0 local y0 = floor(top) local fy = top - y0 for k = 1, 9 do local x, y = x0 + shape[k], y0 + k local ax, ay = 1 - fx, 1 - fy blend(x, y, STEAM[1], STEAM[2], STEAM[3], a * ax * ay) blend(x + 1, y, STEAM[1], STEAM[2], STEAM[3], a * fx * ay) blend(x, y + 1, STEAM[1], STEAM[2], STEAM[3], a * ax * fy) blend(x + 1, y + 1, STEAM[1], STEAM[2], STEAM[3], a * fx * fy) end end local POSE = {} for i, deg in ipairs({ 22, 50, 80, 100, 130, 158 }) do local r = deg * 3.14159 / 180 local pts = {} for k = 0, 8 do pts[#pts + 1] = { floor(45.5 + k * cos(r)), floor(49 - k * sin(r) * 0.9) } end POSE[i] = pts end local SLOT, STEP_F = 7, 3 local function draw_page(t) local n = floor(t / SLOT) local off = 3 + (n % 3) * 0.7 local u = t - n * SLOT - off if u < 0 then return end local k = floor(u * FPS / STEP_F) + 1 if k > #POSE then return end if n % 2 == 1 then k = #POSE + 1 - k end local pts = POSE[k] for i = 1, #pts do rect(pts[i][1], pts[i][2], 2, 2, c3(PAGE)) rect(pts[i][1], pts[i][2] + 2, 2, 1, c3(PAGE_D)) end end function render() local lamp = cfg.lamp ~= false if BG_KEY ~= lamp then build_bg(lamp); BG_KEY = lamp end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame / FPS local n = cfg.steam or 2 for i = 1, n do draw_wisp(i, n, t) end if cfg.pages ~= false then draw_page(t) end end