info = { type = "image", title = "Shake and burger", category = "food", author = "BRRRO", version = "1.0", license = "MIT", desc = "Dewy milkshake and a steaming burger", api = 44, } local tr = ({ sk = { ["Shake colour"] = "Farba trasenia", ["Steam"] = "Para", ["Sip every"] = "Dúšok každých" }, cs = { ["Shake colour"] = "Barva třesení", ["Steam"] = "Pára", ["Sip every"] = "Doušek každých" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "shake", label = T("Shake colour"), type = "color", default = "#F2A6BE" }, { key = "steam", label = T("Steam"), type = "bool", default = true }, { key = "sip", label = T("Sip every"), type = "int", default = 1, opts = { T("6 s"), T("10 s"), T("16 s") } }, } local px, rect, blend, brect = gfx.px, gfx.rect, gfx.blend, gfx.blend_rect local floor, sin, sqrt, abs = math.floor, math.sin, math.sqrt, math.abs 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 function mix(a, b, t) return a + (b - a) * t end local function mix3(c1, c2, t) return mix(c1[1], c2[1], t), mix(c1[2], c2[2], t), mix(c1[3], c2[3], t) end local function ramp(dk, md, lt, t) if t < 0.5 then return mix3(dk, md, t * 2) end return mix3(md, lt, t * 2 - 1) end local LX, LY, LZ = -0.45, -0.62, 0.64 local HX, HY, HZ = -0.249, -0.343, 0.906 local function blob(cx, cy, rx, ry, rz, dk, md, lt, sp, ylo, yhi) for y = floor(cy - ry - 1), floor(cy + ry + 1) do if (not ylo or y >= ylo) and (not yhi or y <= yhi) then local ey = (y + 0.5 - cy) / ry for x = floor(cx - rx - 1), floor(cx + rx + 1) do local ex = (x + 0.5 - cx) / rx local q = ex * ex + ey * ey if q < 1.12 then local nx, ny, nz = ex / rx, ey / ry, (q < 1 and sqrt(1 - q) or 0) / rz local inv = 1 / sqrt(nx * nx + ny * ny + nz * nz) local t = 0.5 + 0.5 * (nx * LX + ny * LY + nz * LZ) * inv local r, g, b = ramp(dk, md, lt, t) local s = (nx * HX + ny * HY + nz * HZ) * inv if s > 0.6 then s = s ^ sp r, g, b = mix(r, 255, s), mix(g, 255, s), mix(b, 255, s) end if q < 0.98 then px(x, y, r, g, b) else blend(x, y, r, g, b, (1.12 - q) / 0.14) end end end end end end local function ellipse(cx, cy, rx, ry, r, g, b, a) for y = floor(cy - ry), floor(cy + ry) do local k = (y + 0.5 - cy) / ry if k * k < 1 then local hw = rx * sqrt(1 - k * k) local x0 = floor(cx - hw + 0.5) brect(x0, y, floor(cx + hw + 0.5) - x0, 1, r, g, b, a) end end end local function fpx(x, y, r, g, b, a) local ix = floor(x) local f = x - ix blend(ix, y, r, g, b, a * (1 - f)) blend(ix + 1, y, r, g, b, a * f) end local LD, LM, LL = { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } local STEAM = true local SIP_S = 10 local BUN_D, BUN_M, BUN_L = { 150, 84, 30 }, { 216, 144, 60 }, { 248, 198, 112 } local CRM_D, CRM_M, CRM_L = { 196, 168, 186 }, { 250, 238, 232 }, { 255, 252, 246 } local function wall(y) local t = y / 41 return mix(62, 118, t), mix(112, 166, t), mix(134, 172, t) end local function table_at(y) local t = (y - 42) / 21 return mix(238, 204, t), mix(212, 166, t), mix(170, 118, t) end local function bg_at(y) if y < 42 then return wall(y) end return table_at(y) end local GCX = 16 local function ghw(y) return 10.5 - 0.06 * (y - 21) end local function glass_px(x, y, liquid) local hw = ghw(y + 0.5) local u = (x + 0.5 - GCX) / hw local au = u < 0 and -u or u if au > 1 then return end local r, g, b if liquid then local d = -0.55 * u + 0.83 * sqrt(1 - u * u) r, g, b = ramp(LD, LM, LL, 0.5 + 0.5 * d) local k = 1 - 0.16 * (y - 24) / 30 r, g, b = r * k, g * k, b * k else r, g, b = bg_at(y) r, g, b = mix(r, 236, 0.14), mix(g, 244, 0.14), mix(b, 246, 0.14) end local sa = 0 if u > -0.66 and u < -0.5 then sa = (1 - abs(u + 0.58) / 0.08) * 0.5 local f = (y - 25) / 4 if f < 1 then sa = sa * (f > 0 and f or 0) end f = (51 - y) / 4 if f < 1 then sa = sa * (f > 0 and f or 0) end elseif u > 0.7 and u < 0.84 then sa = (1 - abs(u - 0.77) / 0.07) * 0.22 end if not liquid then sa = sa * 0.7 end if sa > 0 then r, g, b = mix(r, 255, sa), mix(g, 255, sa), mix(b, 255, sa) end if au > 0.9 then local a = 0.35 + 0.4 * (au - 0.9) / 0.1 r, g, b = mix(r, 232, a), mix(g, 250, a), mix(b, 252, a) end if y >= 52 then r, g, b = mix(r, 222, 0.45), mix(g, 240, 0.45), mix(b, 246, 0.45) if y == 54 then r, g, b = r * 0.8, g * 0.85, b * 0.9 end end px(x, y, r, g, b) end local CUR, BG, GAP = nil, nil, nil local stage = 0 local STAGES = {} STAGES[1] = function() for y = 0, 41 do rect(0, y, W, 1, wall(y)) end for y = 42, H - 1 do rect(0, y, W, 1, table_at(y)) end rect(0, 42, W, 1, 252, 240, 214) local discs = { { 50, 13, 10 }, { 33, 7, 5 } } for i = 1, #discs do local d = discs[i] ellipse(d[1], d[2], d[3] + 1, d[3] + 1, 255, 244, 214, 0.04) ellipse(d[1], d[2], d[3], d[3], 255, 244, 214, 0.05) end for i = 1, 3 do ellipse(16, 56, 14 - i * 2, 3.4 - i * 0.5, 70, 40, 30, 0.10) ellipse(47, 57, 18 - i * 2.5, 3.6 - i * 0.5, 70, 40, 30, 0.10) end end STAGES[2] = function() for y = 24, 39 do for x = 4, 28 do glass_px(x, y, true) end end end STAGES[3] = function() for y = 40, 54 do for x = 4, 28 do glass_px(x, y, true) end end for x = 6, 26 do local hw = ghw(24.5) if abs(x + 0.5 - GCX) < hw - 1 then blend(x, 24, 255, 226, 236, 0.45) end end for i = 1, 16 do local h = hash32(i * 0x9E3779B1) local x, y = 7 + umod(h, 18), 28 + umod(h >> 8, 22) if abs(x + 0.5 - GCX) < ghw(y) - 2 then blend(x, y, 255, 255, 255, 0.7) blend(x, y + 1, 110, 50, 80, 0.22) end end end STAGES[4] = function() local prow = { { 126, 68, 42 }, { 100, 54, 36 }, { 78, 42, 30 }, { 78, 42, 30 }, { 58, 32, 24 } } for i = 1, 5 do local c = prow[i] for x = 34, 60 do local n = (hash32(x * 131 + i * 977) & 15) - 8 px(x, 46 + i, c[1] + n, c[2] + n * 0.6, c[3] + n * 0.4) end end rect(32, 46, 31, 1, 255, 208, 56) rect(32, 47, 31, 1, 238, 166, 24) rect(34, 48, 3, 2, 238, 166, 24); px(34, 50, 224, 146, 20) rect(57, 48, 3, 3, 238, 166, 24); px(58, 51, 224, 146, 20) px(35, 46, 255, 240, 170); px(50, 46, 255, 236, 150); px(58, 46, 255, 240, 170) rect(33, 44, 29, 1, 232, 72, 52) rect(34, 45, 27, 1, 178, 34, 36) brect(40, 44, 5, 1, 255, 170, 150, 0.6) px(48, 45, 250, 196, 120); px(54, 44, 250, 196, 120) for x = 31, 62 do local yb = 43 + floor(1.1 * sin(x * 0.9) + 0.9 * sin(x * 2.1 + 1) + 0.5) if yb < 43 then yb = 43 end local crest = sin(x * 0.9) > 0.3 rect(x, 41, 1, 1, crest and 150 or 128, crest and 222 or 204, crest and 92 or 74) rect(x, 42, 1, yb - 41, crest and 104 or 88, crest and 184 or 164, crest and 58 or 48) rect(x, yb, 1, 1, 54, 128, 42) end end STAGES[5] = function() blob(47, 42, 14.2, 11, 10, BUN_D, BUN_M, BUN_L, 18, 31, 41) end STAGES[6] = function() blob(47, 51.6, 13.6, 5, 6, BUN_D, BUN_M, BUN_L, 18, 52, 56) local k = 0 for i = 1, 40 do local h = hash32(i * 0x85EBCA6B) local x, y = 34 + umod(h, 26), 32 + umod(h >> 8, 8) local ex, ey = (x - 47) / 13, (y - 42) / 10 if ex * ex + ey * ey < 0.62 and k < 11 then k = k + 1 px(x, y, 252, 234, 190); px(x + 1, y, 244, 218, 166) blend(x, y + 1, 120, 70, 30, 0.35) end end end STAGES[7] = function() blob(16, 19.5, 11.2, 5, 7, CRM_D, CRM_M, CRM_L, 24, 15, 23) blob(16, 15.5, 8.4, 3.8, 6, CRM_D, CRM_M, CRM_L, 24) end STAGES[8] = function() blob(16.5, 12.6, 5.8, 3.2, 5, CRM_D, CRM_M, CRM_L, 24) blob(17, 10.4, 3.2, 2.6, 3.4, CRM_D, CRM_M, CRM_L, 24) end STAGES[9] = function() for k = 0, 14 do local x, y = 22 + floor(k * 0.4), 16 - k local red = floor((k + 1) / 3) % 2 == 0 if red then px(x, y, 238, 70, 78); px(x + 1, y, 176, 28, 44) else px(x, y, 255, 255, 255); px(x + 1, y, 214, 214, 226) end end CUR = gfx.snapshot(0, 0, W, H) for y = 24, 33 do for x = 4, 28 do glass_px(x, y, false) end end for y = 24, 33 do px(19, y, 240, 90, 96); px(20, y, 190, 40, 56) end GAP = gfx.snapshot(4, 24, 25, 10) gfx.blit_rgb(CUR, 0, 0, W, H) end local DROPS = { { 11, 6.0, 0.0 }, { 20, 8.5, 0.37 }, { 15, 5.0, 0.71 } } local function sin2(x) local s = sin(x); return s * s end local function draw_drops(t) for i = 1, #DROPS do local d = DROPS[i] local p = (t / (d[2] * STEP_HZ) + d[3]) % 1 local yh = 27 + 24 * (p - 0.0637 * sin(4 * math.pi * p)) local fade = p > 0.9 and (1 - p) / 0.1 or 1 local y0 = floor(yh) local f = yh - y0 local x = d[1] brect(x, 27, 1, y0 - 27, 255, 255, 255, 0.16 * fade) blend(x, y0, 255, 255, 255, 0.85 * (1 - f) * fade) blend(x, y0 + 1, 255, 255, 255, 0.85 * fade) blend(x, y0 + 2, 110, 50, 80, 0.3 * (0.4 + f) * fade) end end local function disc(cx, cy, r, cr, cg, cb) for j = -floor(r), floor(r) do local hw = sqrt(r * r - j * j) local xl, xr = cx - hw, cx + hw local y = floor(cy) + j local a, b2 = floor(xl + 1), floor(xr) if b2 >= a then rect(a, y, b2 - a + 1, 1, cr, cg, cb) end blend(a - 1, y, cr, cg, cb, a - xl) blend(b2 + 1, y, cr, cg, cb, xr - b2) end end local function draw_cherry(cx, cy) disc(cx, cy, 3.3, 142, 12, 32) disc(cx - 0.5, cy - 0.6, 2.5, 214, 30, 50) fpx(cx - 1.6, floor(cy - 1.5), 255, 190, 190, 0.9) fpx(cx - 1.0, floor(cy - 2.0), 255, 190, 190, 0.7) for s = 0, 6 do local k = s / 6 fpx(cx + 0.4 + 3.6 * k - 1.2 * sin(3.14159 * k), floor(cy - 3 - 4.6 * k + 0.5), 96, 112, 40, 1) end end local function draw_straw_fill(fill) if fill <= 0.05 then return end local n = floor(fill) local fr = fill - n for k = 0, n do local x, y = 22 + floor(k * 0.4), 16 - k local a = (k == n) and fr or 1 blend(x, y, LM[1], LM[2], LM[3], 0.82 * a) blend(x + 1, y, LD[1], LD[2], LD[3], 0.82 * a) end end local function draw_steam(t) for i = 0, 2 do local x0 = 47 + (i - 1) * 7 for y = 30, 8, -2 do local a = (30 - y) / 22 local al = 0.34 * sin(3.14159 * a) ^ 0.7 * (0.5 + 0.5 * sin(y * 0.55 - t * 0.17 + i * 2.1)) if al > 0.01 then local w = 2 + floor(a * 2.5) local x = x0 + 2.4 * sin(y * 0.3 - t * 0.07 + i * 1.7) * (0.4 + a) brect(floor(x - w / 2 + 0.5), y, w, 2, 255, 252, 246, al) end end end end function on_settings() local c = cfg.shake or { r = 242, g = 166, b = 190 } LM[1], LM[2], LM[3] = c.r, c.g, c.b LD[1], LD[2], LD[3] = c.r * 0.66, c.g * 0.6, c.b * 0.72 + 12 LL[1], LL[2], LL[3] = mix(c.r, 255, 0.5), mix(c.g, 255, 0.5), mix(c.b, 255, 0.5) STEAM = cfg.steam ~= false local sip = cfg.sip or 1 SIP_S = sip == 0 and 6 or (sip == 1 and 10 or 16) stage, BG = 0, nil end function render() if not BG then stage = stage + 1 if stage > 1 then gfx.blit_rgb(CUR, 0, 0, W, H) end STAGES[stage]() CUR = gfx.snapshot(0, 0, W, H) if stage == #STAGES then BG = CUR end if not BG then gfx.ready(false) end return end local t = frame * STEP_HZ // FPS gfx.blit_rgb(BG, 0, 0, W, H) local per = SIP_S * STEP_HZ local tau = t % per local tsip = 3.6 * STEP_HZ local lvl, fill = 0, 0 if tau < tsip then local s = sin2(3.14159 * tau / tsip) lvl, fill = 6 * s, 10 * s * s end if lvl > 0.02 then local y1 = floor(lvl) if y1 > 0 then gfx.clip(4, 24, 25, y1) gfx.blit_rgb(GAP, 4, 24, 25, 10) gfx.clip() end local f = lvl - y1 local hw = ghw(24 + y1 + 0.5) - 1 brect(floor(GCX - hw + 0.5), 24 + y1, floor(2 * hw + 0.5), 1, LM[1], LM[2], LM[3], 1 - f) end draw_straw_fill(fill) local tw = (tau - tsip - 0.2 * STEP_HZ) / STEP_HZ local amp = 0 if tw > 0 then amp = 1.5 * 2.718 ^ (-tw / 0.8) * sin(TAU * tw / 0.75) end local idle = 0.25 * sin(TAU * t / (2.6 * STEP_HZ)) draw_cherry(15.5 + amp + idle, 7.4 + 0.15 * abs(amp)) draw_drops(t) if STEAM then draw_steam(t) end end