info = { type = "image", title = "Iced matcha", category = "food", author = "BRRRO", version = "1.0", license = "MIT", desc = "Bubbles rise and ice bobs in a matcha glass", api = 33, } local ltr = ({ sk = { ["Top layer"] = "Vrchná vrstva", ["Bottom layer"] = "Spodná vrstva", ["Bubbles"] = "Bubliny" }, cs = { ["Top layer"] = "Vrchní vrstva", ["Bottom layer"] = "Spodní vrstva", ["Bubbles"] = "Bubliny" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "top", label = LT("Top layer"), type = "color", default = "#8CC850" }, { key = "bot", label = LT("Bottom layer"), type = "color", default = "#F28CB4" }, { key = "bubbles", label = LT("Bubbles"), type = "int", min = 0, max = 16, default = 10 }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, sin = math.floor, math.sin local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local TAU = 6.28318 local WALL, WALL_DOT = { 36, 82, 110 }, { 54, 104, 136 } local TABLE_E, TABLE, TABLE_F = { 232, 184, 128 }, { 196, 140, 90 }, { 150, 100, 62 } local RIM, EDGE_L, EDGE_R = { 226, 242, 250 }, { 206, 230, 242 }, { 138, 172, 192 } local BASE, BASE_L = { 168, 200, 216 }, { 214, 236, 246 } local STRAW_R, STRAW_W = { 226, 58, 74 }, { 244, 238, 232 } local BERRY, BERRY_L, SEED = { 210, 36, 60 }, { 246, 128, 140 }, { 252, 228, 150 } local MINT, MINT_L = { 46, 150, 76 }, { 104, 206, 112 } local GT, LS, MID, LB, GB = 10, 19, 35, 50, 56 local function xl(y) return 19 + (y - GT) * 2 // (GB - GT) end local function xr(y) return 44 - (y - GT) * 2 // (GB - GT) end local function c3(c) return c[1], c[2], c[3] end local function mix(c, d, k) return floor(c[1] + (d[1] - c[1]) * k), floor(c[2] + (d[2] - c[2]) * k), floor(c[3] + (d[3] - c[3]) * k) end local WHITE, BLACK = { 255, 255, 255 }, { 0, 0, 0 } local TOP, BOT = { 140, 200, 80 }, { 242, 140, 180 } local BG = nil local function build_bg() rect(0, 0, W, 52, c3(WALL)) for y = 3, 50, 6 do for x = (y // 6) % 2 * 4 + 2, W - 1, 8 do px(x, y, c3(WALL_DOT)) end end rect(0, 52, W, 1, c3(TABLE_E)) rect(0, 53, W, 6, c3(TABLE)) rect(0, 59, W, 5, c3(TABLE_F)) blend_rect(40, 55, 12, 1, 0, 0, 0, 0.28) blend_rect(42, 56, 7, 1, 0, 0, 0, 0.28) local tr, tg, tb = c3(TOP) local br, bg, bb = c3(BOT) local tdr, tdg, tdb = mix(TOP, BLACK, 0.22) local bdr, bdg, bdb = mix(BOT, BLACK, 0.22) for y = GT + 1, GB do local a, b = xl(y), xr(y) if y < LS then blend_rect(a + 1, y, b - a - 1, 1, 255, 255, 255, 0.16) elseif y <= LB then local r1, g1, b1, r2, g2, b2 = tr, tg, tb, tdr, tdg, tdb if y > MID then r1, g1, b1, r2, g2, b2 = br, bg, bb, bdr, bdg, bdb end rect(a + 1, y, b - a - 1, 1, r1, g1, b1) px(a + 1, y, r2, g2, b2); px(b - 1, y, r2, g2, b2) else rect(a + 1, y, b - a - 1, 1, c3(BASE)) end px(a, y, c3(EDGE_L)); px(b, y, c3(EDGE_R)) end rect(xl(GT), GT, xr(GT) - xl(GT) + 1, 1, c3(RIM)) rect(xl(GB) + 1, LB + 1, xr(GB) - xl(GB) - 1, 1, c3(BASE_L)) rect(xl(LS) + 1, LS, xr(LS) - xl(LS) - 1, 1, mix(TOP, WHITE, 0.4)) for x = xl(MID) + 1, xr(MID) - 1 do local h = hash32(x * 0x9E3779B1) local yb = MID + umod(h, 3) if yb > MID then rect(x, MID + 1, 1, yb - MID, tr, tg, tb) end if (h >> 8) & 1 == 1 then px(x, yb + 2, tr, tg, tb) end end for i = 1, 7 do local h = hash32(i * 0x85EBCA6B) local x, y = 23 + umod(h, 16), 41 + umod(h >> 8, 9) rect(x, y, 2, 1, c3(BERRY)); px(x, y + 1, c3(BERRY)) end for y = 0, 31 do local x = 43 - y * 5 // 24 local c = (y // 3) % 2 == 0 and STRAW_R or STRAW_W if y < LS then rect(x, y, 2, 1, c3(c)) else blend_rect(x, y, 2, 1, c[1], c[2], c[3], 0.45) end end px(38, 17, c3(MINT)); rect(39, 16, 2, 2, c3(MINT_L)); px(41, 15, c3(MINT_L)); px(40, 18, c3(MINT)) local BERRY_ROWS = { { 6, 18, 3 }, { 7, 17, 5 }, { 8, 17, 6 }, { 9, 17, 6 }, { 10, 18, 5 }, { 11, 19, 3 }, { 12, 20, 1 } } for i = 1, #BERRY_ROWS do local r = BERRY_ROWS[i] rect(r[2], r[1], r[3], 1, c3(BERRY)) end rect(19, 8, 2, 2, c3(BERRY_L)); px(18, 9, c3(BERRY_L)) px(18, 7, c3(SEED)); px(21, 8, c3(SEED)); px(20, 10, c3(SEED)) for i = 1, 18 do local h = hash32(i * 0xC2B2AE35) local y = 13 + umod(h, 36) blend(xl(y) + 2 + umod(h >> 8, xr(y) - xl(y) - 3), y, 255, 255, 255, 0.4) end BG = gfx.snapshot(0, 0, W, H) end function on_settings() local t, b = cfg.top or { r = 140, g = 200, b = 80 }, cfg.bot or { r = 242, g = 140, b = 180 } TOP, BOT = { t.r, t.g, t.b }, { b.r, b.g, b.b } BG = nil end local ICE = { { 22, 6, 6, 15.5, 0.7, 2.8, 0.0 }, { 29, 5, 5, 16.5, 0.6, 2.3, 1.7 }, { 35, 6, 5, 15.8, 0.8, 3.1, 3.9 } } local function draw_ice(t) for i = 1, #ICE do local c = ICE[i] local x, w, h = c[1], c[2], c[3] local y = c[4] + c[5] * sin(t * TAU / (c[6] * STEP_HZ) + c[7]) local yi = floor(y) local f = y - yi blend_rect(x, yi, w, 1, 232, 246, 255, 0.55 * (1 - f)) blend_rect(x, yi + 1, w, h - 1, 232, 246, 255, 0.5) blend_rect(x, yi + h, w, 1, 232, 246, 255, 0.5 * f) local ty = floor(y + 0.5) blend_rect(x, ty, w, 1, 255, 255, 255, 0.5) blend_rect(x, ty + 1, 1, h - 2, 255, 255, 255, 0.35) px(x + 1, ty + 1, 255, 255, 255) end end local BV, BOFF, BGAP = {}, {}, {} for i = 1, 16 do local h = hash32(i * 0x27D4EB2F) BV[i] = (6 + umod(h, 60) / 10.0) / STEP_HZ BGAP[i] = 34 + umod(h >> 8, 24) BOFF[i] = umod(h >> 16, BGAP[i]) end local function draw_bubbles(t, n) for i = 1, n do local pos = t * BV[i] + BOFF[i] local pass = floor(pos / BGAP[i]) local p = pos - pass * BGAP[i] local x = 23 + umod(hash32(pass * 0x9E3779B1 + i * 0x85EBCA6B), 18) if p < LB - LS - 1 then local y = LB - p local yi = floor(y) local f = y - yi blend(x, yi, 255, 255, 255, 0.75 * (1 - f)) blend(x, yi + 1, 255, 255, 255, 0.75 * f) elseif p < LB - LS + 1 then blend(x - 1, LS, 255, 255, 255, 0.7); blend(x + 1, LS, 255, 255, 255, 0.7) end end end local DP, DOFF = { 173, 211, 241 }, { 0, 71, 140 } local FORM, SLIDE = 45, 50 local function draw_drops(t) for i = 1, #DP do local P = DP[i] local q = t + DOFF[i] local pass, u = q // P, q % P local h = hash32(pass * 0x9E3779B1 + i * 0xC2B2AE35) local y0 = 22 + umod(h >> 8, 8) local x = xl(y0) + 3 + umod(h, 17) local L = 12 + umod(h >> 16, 12) if y0 + L > LB then L = LB - y0 end if u < FORM then blend(x, y0, 255, 255, 255, 0.25 + 0.55 * u / FORM) else local s = (u - FORM) / SLIDE local trail = 0.2 if s > 1 then trail = 0.2 * (1 - (u - FORM - SLIDE) / (P - FORM - SLIDE)) s = 1 end local y = y0 + L * s * s * (3 - 2 * s) local yi = floor(y) local f = y - yi if yi > y0 then blend_rect(x, y0, 1, yi - y0, 255, 255, 255, trail) end blend(x, yi, 255, 255, 255, 0.85 * (1 - f) + 0.15) blend(x, yi + 1, 255, 255, 255, 0.85 * f) end end end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame * STEP_HZ // FPS draw_bubbles(t, cfg.bubbles or 10) draw_ice(t) draw_drops(t) end