info = { type = "image", title = "Milkshake", category = "food", author = "BRRRO", version = "1.0", license = "MIT", desc = "A diner milkshake with bubbles and a drip", api = 33, } local tr = ({ sk = { ["Flavour"] = "Príchuť", ["Strawberry"] = "Jahodová", ["Chocolate"] = "Čokoláda", ["Mint"] = "Mätová", ["Bubbles"] = "Bubliny" }, cs = { ["Flavour"] = "Příchuť", ["Strawberry"] = "Jahodová", ["Chocolate"] = "Čokoláda", ["Mint"] = "Mátová", ["Bubbles"] = "Bubliny" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "flavor", label = T("Flavour"), type = "int", default = "strawberry", opts = { keys = { "strawberry", "chocolate", "mint" }, T("Strawberry"), T("Chocolate"), T("Mint") } }, { key = "bubbles", label = T("Bubbles"), type = "int", min = 0, max = 10, default = 6 }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, min = math.floor, math.min local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local FLAVORS = { strawberry = { drink = { 246, 136, 168 }, shade = { 218, 96, 136 }, light = { 255, 214, 226 }, syrup = { 206, 30, 72 }, wall = { 148, 212, 204 }, dot = { 178, 232, 224 } }, chocolate = { drink = { 150, 92, 60 }, shade = { 118, 68, 42 }, light = { 214, 172, 136 }, syrup = { 96, 50, 28 }, wall = { 248, 196, 206 }, dot = { 255, 222, 230 } }, mint = { drink = { 160, 230, 194 }, shade = { 116, 200, 160 }, light = { 226, 255, 238 }, syrup = { 96, 50, 28 }, wall = { 196, 180, 238 }, dot = { 218, 206, 252 }, chips = { 74, 42, 24 } }, } local FL = FLAVORS.strawberry local NBUB = 6 local CREAM, CREAM_S, WHITE = { 255, 246, 234 }, { 230, 206, 198 }, { 255, 255, 255 } local SPRINK = { { 255, 84, 140 }, { 255, 206, 50 }, { 80, 164, 255 }, { 110, 214, 100 }, { 255, 146, 40 }, { 190, 110, 255 } } local GL, GR = 15, 36 local D_TOP, D_BOT = 30, 47 local CR = { { 10, 26, 27 }, { 11, 25, 28 }, { 12, 24, 27 }, { 13, 22, 29 }, { 14, 21, 30 }, { 15, 21, 30 }, { 16, 22, 29 }, { 17, 21, 30 }, { 18, 19, 32 }, { 19, 18, 33 }, { 20, 18, 33 }, { 21, 18, 33 }, { 22, 19, 32 }, { 23, 18, 33 }, { 24, 16, 35 }, { 25, 15, 36 }, { 26, 14, 37 }, { 27, 14, 37 }, { 28, 14, 37 }, { 29, 15, 36 }, } local TIER_BOT = { [11] = true, [16] = true, [22] = true, [29] = true } local TIER_TOP = { [12] = true, [17] = true, [23] = true } local function c3(c) return c[1], c[2], c[3] end local SP = {} do local i = 0 while #SP < 18 and i < 400 do i = i + 1 local h = hash32(i * 0x9E3779B1) local r = CR[3 + umod(h, #CR - 2)] if not TIER_BOT[r[1]] and r[3] - r[2] > 4 then local x = r[2] + 2 + umod(h >> 8, r[3] - r[2] - 3) local dup = false for k = 1, #SP do local s = SP[k] if (s[1] - x) * (s[1] - x) + (s[2] - r[1]) * (s[2] - r[1]) < 5 then dup = true end end if not dup then SP[#SP + 1] = { x, r[1], SPRINK[1 + #SP % #SPRINK] } end end end end local BG = nil local function build_bg() rect(0, 0, W, 49, c3(FL.wall)) for j = 0, 5 do for x = (j % 2 == 0) and 3 or 7, W - 1, 8 do rect(x, 3 + 8 * j, 2, 2, c3(FL.dot)) end end rect(0, 49, W, 1, 200, 194, 190) rect(0, 50, W, 6, 238, 234, 228) px(4, 52, 214, 208, 206); px(5, 52, 214, 208, 206); px(46, 54, 214, 208, 206) px(58, 51, 214, 208, 206); px(59, 52, 214, 208, 206) rect(0, 56, W, 1, 226, 230, 238) rect(0, 57, W, 1, 150, 156, 170) rect(0, 58, W, 6, 206, 46, 62) rect(0, 61, W, 1, 244, 240, 236) rect(13, 52, 26, 1, 252, 252, 250) rect(11, 53, 30, 1, 252, 252, 250) rect(13, 54, 26, 1, 252, 252, 250) for x = 12, 40, 3 do px(x, 54, 226, 220, 222) end rect(43, 37, 13, 16, 172, 180, 194) rect(42, 35, 15, 2, 222, 228, 238) rect(44, 36, 11, 1, c3(FL.shade)) rect(45, 38, 1, 13, 236, 240, 248) rect(53, 37, 2, 16, 128, 136, 152) rect(43, 52, 13, 1, 110, 116, 132) px(48, 41, 240, 244, 250); px(50, 45, 240, 244, 250); px(47, 48, 240, 244, 250) for y = 4, 16 do local x = 31 + (16 - y) * 6 // 12 local red = ((16 - y) // 2) % 2 == 0 if red then rect(x, y, 2, 1, 228, 40, 64) else rect(x, y, 2, 1, 250, 250, 250) end end rect(37, 2, 2, 2, 250, 250, 250) for x = 39, 45 do if (x // 2) % 2 == 0 then rect(x, 2, 1, 2, 228, 40, 64) else rect(x, 2, 1, 2, 250, 250, 250) end end rect(GL + 1, D_TOP, GR - GL - 1, D_BOT - D_TOP + 1, c3(FL.drink)) rect(GR - 4, D_TOP, 4, D_BOT - D_TOP + 1, c3(FL.shade)) rect(GL + 1, D_BOT, GR - GL - 1, 1, c3(FL.shade)) if FL.chips then for i = 1, 9 do local h = hash32(i * 0x85EBCA6B + 7) px(GL + 2 + umod(h, 17), D_TOP + 2 + umod(h >> 8, 15), c3(FL.chips)) end end blend_rect(GL, 25, 1, 27, 255, 255, 255, 0.55) blend_rect(GR, 25, 1, 27, 255, 255, 255, 0.55) blend_rect(GL + 1, 48, GR - GL - 1, 4, 220, 240, 255, 0.4) blend_rect(GL + 1, 52, GR - GL - 1, 1, 255, 255, 255, 0.55) blend_rect(GL + 3, D_TOP + 1, 1, 15, 255, 255, 255, 0.5) blend_rect(GL + 4, D_TOP + 2, 1, 5, 255, 255, 255, 0.35) blend_rect(GL + 2, 49, 3, 1, 255, 255, 255, 0.5) for i = 1, #CR do local y, x0, x1 = CR[i][1], CR[i][2], CR[i][3] if TIER_BOT[y] then rect(x0, y, x1 - x0 + 1, 1, c3(CREAM_S)) else rect(x0, y, x1 - x0 + 1, 1, c3(CREAM)) px(x1, y, c3(CREAM_S)) if TIER_TOP[y] then rect(x0 + 1, y, 3, 1, c3(WHITE)) end end end local S = FL.syrup rect(17, 25, 1, 4, c3(S)); rect(34, 24, 1, 3, c3(S)); rect(28, 29, 1, 2, c3(S)) rect(20, 19, 1, 3, c3(S)); rect(31, 18, 1, 2, c3(S)); px(24, 13, c3(S)); px(24, 14, c3(S)) for k = 1, #SP do px(SP[k][1], SP[k][2], c3(SP[k][3])) end BG = gfx.snapshot(0, 0, W, H) end local BX, BV, BO = {}, {}, {} for i = 1, 10 do local h = hash32(i * 0x9E3779B1 + 99) BX[i] = GL + 3 + umod(h, 14) BV[i] = 0.10 + (h >> 8 & 0xFF) / 255 * 0.18 BO[i] = umod(h >> 16, 150) end local function draw_bubbles(t) local r, g, b = c3(FL.light) local span = D_BOT - D_TOP - 1 for i = 1, NBUB do local y = D_BOT - 1 - (t * BV[i] + BO[i]) % span local iy = floor(y) local f = y - iy blend(BX[i], iy, r, g, b, 0.9 * (1 - f)) blend(BX[i], iy + 1, r, g, b, 0.9 * f) end end local DRIP = 210 local function draw_drip(t) local c = t // DRIP local q = t - c * DRIP local x = (c % 2 == 0) and GR or GL local r, g, b = c3(FL.syrup) local a = q > 190 and (DRIP - q) / 20 or 1 local y0 = 30 if q < 18 then blend(x, y0, r, g, b, a * (0.4 + q / 30)) if q >= 9 then blend(x, y0 + 1, r, g, b, a * (q - 9) / 9) end return end local p = min(1, (q - 18) / 120) local y = y0 + 1 + 19 * p * p local iy = floor(y) local f = y - iy if iy > y0 then blend_rect(x, y0, 1, iy - y0, r, g, b, 0.7 * a) end blend_rect(x, iy, 1, 2, r, g, b, a) if f > 0.05 then blend(x, iy + 2, r, g, b, f * a) end if p >= 1 then local w = min(3, 1 + (q - 138) // 8) blend_rect(x - w // 2, 53, w, 1, r, g, b, a) end end local function star(x, y, q) if q < 2 or q > 8 then blend(x, y, 255, 255, 255, 0.6); return end px(x, y, 255, 255, 255) if q >= 3 and q <= 7 then px(x - 1, y, 255, 255, 255); px(x + 1, y, 255, 255, 255) px(x, y - 1, 255, 255, 255); px(x, y + 1, 255, 255, 255) end if q >= 4 and q <= 6 then blend(x - 2, y, 255, 255, 255, 0.6); blend(x + 2, y, 255, 255, 255, 0.6) blend(x, y - 2, 255, 255, 255, 0.6); blend(x, y + 2, 255, 255, 255, 0.6) end end local WALL_STARS = { { 6, 10, 0, 70 }, { 56, 22, 29, 83 }, { 8, 40, 51, 61 }, { 58, 6, 13, 97 } } local function draw_sparkle(t) local f3 = t // 3 for i = 1, #SP do if (f3 + i * 7) % 13 == 0 then px(SP[i][1], SP[i][2], 255, 255, 255) end end local k = 1 + umod(hash32((t // 24) * 0x9E3779B1 + 5), #SP) local q = t % 24 if q < 11 then star(SP[k][1], SP[k][2], q) end for i = 1, #WALL_STARS do local s = WALL_STARS[i] local qq = (t + s[3]) % s[4] if qq < 11 then star(s[1], s[2], qq) end end end local WOB = { -1, -1, 1, 1, -1, 1, 0 } local function draw_cherry(t) local q = t % 150 local o = q < 21 and WOB[q // 3 + 1] or 0 rect(26 + o, 5, 3, 5, 222, 24, 48) rect(25 + o, 6, 5, 3, 222, 24, 48) px(29 + o, 8, 160, 12, 36); px(28 + o, 9, 160, 12, 36); px(27 + o, 9, 160, 12, 36) px(26 + o, 6, 255, 176, 186) px(27 + o, 4, 70, 120, 40); px(28 + o, 3, 70, 120, 40) px(28 + 2 * o, 2, 70, 120, 40); px(29 + 2 * o, 1, 70, 120, 40) px(30 + 2 * o, 1, 110, 170, 60) end function on_settings() FL = FLAVORS[cfg.flavor] or FLAVORS.strawberry NBUB = cfg.bubbles or 6 BG = nil 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) draw_drip(t) draw_sparkle(t) draw_cherry(t) end