info = { type = "image", title = "Mad lab", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A lab shelf glides by with bubbling potions", api = 33, } local tr = ({ sk = { ["Pan speed"] = "Rýchlosť posunu", ["Still"] = "Stojí", ["Slow"] = "Pomalý", ["Normal"] = "Bežný", ["Fast"] = "Rýchly", ["Bubbles"] = "Bublinky", ["Eye"] = "Oko" }, cs = { ["Pan speed"] = "Rychlost posunu", ["Still"] = "Stojí", ["Slow"] = "Pomalý", ["Normal"] = "Běžný", ["Fast"] = "Rychlý", ["Bubbles"] = "Bublinky", ["Eye"] = "Oko" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "speed", label = T("Pan speed"), type = "int", default = 2, opts = { T("Still"), T("Slow"), T("Normal"), T("Fast") } }, { key = "bubbles", label = T("Bubbles"), type = "bool", default = true }, { key = "eye", label = T("Eye"), type = "bool", default = true }, } local rect, blend, blend_rect, blit_rgb = gfx.rect, gfx.blend, gfx.blend_rect, gfx.blit_rgb local floor, sqrt, abs, max = math.floor, math.sqrt, math.abs, math.max local hash32 = math.hash32 local W, H = gfx.W, gfx.H local PERIOD = 144 local SPEEDS = { 0, 0.22, 0.4, 0.7 } local SHELF = 44 local DK = { 34, 18, 12 } local WALL, STAIN = { 252, 216, 120 }, { 238, 196, 98 } local GLASS = { 255, 244, 214 } local WOOD, WOOD_D, BOARD = { 96, 58, 30 }, { 70, 40, 22 }, { 178, 118, 46 } local RACK = { 158, 100, 26 } local LIQ = { cyan = { 40, 226, 255 }, magenta = { 250, 44, 214 }, orange = { 255, 138, 24 }, purple = { 176, 52, 244 }, green = { 44, 236, 64 }, blue = { 56, 112, 255 }, } local function light(c) return { c[1] + (255 - c[1]) * 0.5, c[2] + (255 - c[2]) * 0.5, c[3] + (255 - c[3]) * 0.5 } end local LIGHT = {} for k, c in pairs(LIQ) do LIGHT[k] = light(c) end local function hs(x0, x1, y, h, c, a) if x1 <= x0 or x1 < -1 or x0 > W + 1 then return end local r, g, b = c[1], c[2], c[3] local i0, i1 = floor(x0), floor(x1) local al = a or 1 if i0 == i1 then blend_rect(i0, y, 1, h, r, g, b, (x1 - x0) * al); return end local s, e = i0 + 1, i1 local cl, cr = i0 + 1 - x0, x1 - i1 if cl > 0.94 then s = i0 elseif cl > 0.06 then blend_rect(i0, y, 1, h, r, g, b, cl * al) end if cr > 0.94 then e = i1 + 1 elseif cr > 0.06 then blend_rect(i1, y, 1, h, r, g, b, cr * al) end if e > s then if a then blend_rect(s, y, e - s, h, r, g, b, a) else rect(s, y, e - s, h, r, g, b) end end end local function chord(r, cy, y) local d1, d2 = y + 0.25 - cy, y + 0.75 - cy local a, b = r * r - d1 * d1, r * r - d2 * d2 return ((a > 0 and sqrt(a) or 0) + (b > 0 and sqrt(b) or 0)) * 0.5 end local function disc(cx, cy, r, c) for y = floor(cy - r), floor(cy + r) do local w = chord(r, cy, y) if w > 0 then hs(cx - w, cx + w, y, 1, c) end end end local function bub(x, y) local ix, iy = floor(x), floor(y) local fx, fy = x - ix, y - iy blend(ix, iy, 255, 255, 255, 0.9 * (1 - fx) * (1 - fy)) blend(ix + 1, iy, 255, 255, 255, 0.9 * fx * (1 - fy)) blend(ix, iy + 1, 255, 255, 255, 0.9 * (1 - fx) * fy) blend(ix + 1, iy + 1, 255, 255, 255, 0.9 * fx * fy) end local function bubbles(x0, x1, ly, bottom, n, seed) if cfg.bubbles == false then return end local span = bottom - ly - 1 for k = 1, n do local u = (frame * (0.3 + (k % 3) * 0.08) + k * 37 + seed * 11) % span local x = x0 + (x1 - x0) * (((k * 5 + seed * 3) % 7) + 0.5) / 7 + 0.4 * math.sin(frame * 0.06 + k) bub(x, bottom - 1 - u) end end local function tube_ly(i) return 20 + (i % 3) * 3 end local function tube(ox, key, i) local c = LIQ[key] hs(ox, ox + 7, 10, 33, DK) hs(ox + 1, ox + 6, 43, 1, DK) hs(ox + 1, ox + 6, 11, 32, GLASS) local ly = tube_ly(i) hs(ox + 1, ox + 6, ly, 43 - ly, c) hs(ox + 1, ox + 6, ly, 1, LIGHT[key]) end local function rack(ox) hs(ox + 1, ox + 33, 41, 4, DK) hs(ox + 2, ox + 32, 42, 2, RACK) tube(ox + 3, "cyan", 1); tube(ox + 13, "magenta", 2); tube(ox + 23, "orange", 3) hs(ox, ox + 2, 8, 37, DK); hs(ox + 31, ox + 34, 8, 37, DK) hs(ox + 0.5, ox + 1.5, 9, 35, RACK); hs(ox + 31.5, ox + 33, 9, 35, RACK) hs(ox, ox + 34, 18, 5, DK); hs(ox + 0.5, ox + 33.5, 19, 3, RACK) end local function flask(ox) local cx, cy, r = ox + 14, 29.5, 13 hs(cx - 5.5, cx + 5.5, 3, 2, DK) hs(cx - 4.5, cx + 4.5, 5, 12, DK) hs(cx - 3.5, cx + 3.5, 5, 12, GLASS) local ly = 25 for y = 16, 43 do local wo = chord(r, cy, y) if wo > 0 then hs(cx - wo, cx + wo, y, 1, DK) local wi = chord(r - 1.3, cy, y) if y >= ly then hs(cx - wi, cx + wi, y, 1, y == ly and LIGHT.purple or LIQ.purple) elseif wi > 0 then hs(cx - wi, cx + wi, y, 1, GLASS) end end end end local function beaker(ox) hs(ox - 1, ox + 23, 15, 2, DK) hs(ox, ox + 22, 17, 27, DK) hs(ox + 1, ox + 21, 17, 26, GLASS) hs(ox + 1, ox + 21, 24, 19, LIQ.green) hs(ox + 1, ox + 21, 24, 1, LIGHT.green) for k = 0, 5 do hs(ox + 1, ox + (k % 2 == 0 and 6 or 4), 19 + k * 4, 1, DK) end end local function conical(ox) local cx = ox + 12 hs(cx - 4.5, cx + 4.5, 7, 2, DK) hs(cx - 3.5, cx + 3.5, 9, 11, DK) hs(cx - 2.5, cx + 2.5, 9, 11, GLASS) local ly = 31 for y = 20, 43 do local hw = 3.5 + (y - 20) / 23 * 9 hs(cx - hw - 1, cx + hw + 1, y, 1, DK) hs(cx - hw, cx + hw, y, 1, y >= ly and (y == ly and LIGHT.blue or LIQ.blue) or GLASS) end end local function rack_bub(ox) for i = 1, 3 do bubbles(ox + 3 + (i - 1) * 10 + 1.5, ox + 3 + (i - 1) * 10 + 5.5, tube_ly(i), 43, 2, i) end end local function flask_bub(ox) bubbles(ox + 6, ox + 22, 25, 40, 3, 4) end local function beaker_bub(ox) bubbles(ox + 8, ox + 20, 24, 43, 4, 9) end local function conical_bub(ox) bubbles(ox + 4, ox + 20, 31, 43, 3, 6) end local ITEMS = { { 4, 34, rack, rack_bub }, { 46, 28, flask, flask_bub }, { 86, 23, beaker, beaker_bub }, { 118, 24, conical, conical_bub }, } local EX, EY, ER = 17, 51, 8 local KEY = { 255, 0, 255 } local EYEBG, BG local function build() rect(0, 0, W, SHELF, WALL[1], WALL[2], WALL[3]) rect(0, SHELF, W, 3, BOARD[1], BOARD[2], BOARD[3]) rect(0, SHELF + 3, W, 1, DK[1], DK[2], DK[3]) rect(0, SHELF + 4, W, H - SHELF - 4, WOOD[1], WOOD[2], WOOD[3]) rect(0, 56, W, 1, WOOD_D[1], WOOD_D[2], WOOD_D[3]) BG = gfx.snapshot(0, 0, W, H) rect(EX - 12, EY - 12, 24, 24, KEY[1], KEY[2], KEY[3]) for _, d in ipairs({ { ER + 1.2, DK }, { ER, { 252, 244, 238 } } }) do for y = floor(EY - d[1]), floor(EY + d[1]) do local w = floor(chord(d[1], EY, y) + 0.5) if w > 0 then rect(EX - w, y, 2 * w, 1, d[2][1], d[2][2], d[2][3]) end end end local RED = { 206, 30, 40 } for _, v in ipairs({ { -7, -2 }, { -6, -3 }, { -6, 1 }, { -5, 2 }, { 6, 3 }, { 5, 4 }, { 4, 5 }, { -2, 6 }, { -3, 6 }, { 1, -7 }, { 2, -6 }, { 6, -3 }, { 5, -4 } }) do rect(EX + v[1], EY + v[2], 1, 1, RED[1], RED[2], RED[3]) end for _, v in ipairs({ { -9, 5 }, { -10, 6 }, { -11, 7 }, { -11, 8 } }) do rect(EX + v[1], EY + v[2], 1, 1, 176, 24, 36) end EYEBG = gfx.snapshot(EX - 12, EY - 12, 24, 24) end local LOOK = { { 1, 0 }, { 0.9, -0.4 }, { 0.7, 0.55 }, { 1, 0.15 }, { 0.2, 0.9 }, { 0.3, -0.9 }, { -0.5, 0.2 } } local function gaze(slot) local l = LOOK[math.umod(hash32(slot * 0x9E3779B1), 7) + 1] return l[1], l[2] end local function draw_eye() blit_rgb(EYEBG, EX - 12, EY - 12, 24, 24, KEY[1], KEY[2], KEY[3]) local slot = frame // 75 local t = (frame % 75) / 10 if t > 1 then t = 1 end t = t * t * (3 - 2 * t) local ax, ay = gaze(slot - 1) local bx, by = gaze(slot) local gx, gy = ax + (bx - ax) * t, ay + (by - ay) * t local m = ER - 4.3 local cx, cy = EX + gx * m, EY + gy * m disc(cx, cy, 3.9, { 30, 80, 190 }) disc(cx, cy, 3.2, { 56, 150, 240 }) disc(cx, cy, 1.9, { 8, 8, 18 }) blend(floor(cx - 1.6), floor(cy - 1.8), 255, 255, 255, 0.95) end local STAINS = { { 10, 6, 9, 2 }, { 30, 20, 6, 3 }, { 52, 9, 11, 2 }, { 70, 27, 7, 3 }, { 88, 14, 10, 2 }, { 118, 24, 8, 2 }, { 130, 7, 6, 3 } } local DASH = { 4, 18, 31, 44, 59, 71 } local CH_W, NCH, NPH = 48, 3, 2 local CHUNK, NEXT = {}, 1 local function bake(n) local ph, j = (n - 1) // NCH, (n - 1) % NCH local sh, x0 = ph / NPH, j * CH_W rect(0, 0, CH_W, SHELF, WALL[1], WALL[2], WALL[3]) for i = 1, #STAINS do local s = STAINS[i] hs(s[1] - x0 - sh, s[1] - x0 - sh + s[3], s[2], s[4], STAIN) end for i = 1, #ITEMS do local it = ITEMS[i] local x = it[1] - x0 - sh if x < CH_W + 2 and x + it[2] > -2 then it[3](x) end end CHUNK[n] = gfx.snapshot(0, 0, CH_W, SHELF) end function render() if not BG then build() end if NEXT <= NPH * NCH then bake(NEXT); NEXT = NEXT + 1 end blit_rgb(BG, 0, 0, W, H) local sp = SPEEDS[(cfg.speed or 2) + 1] or 0.4 local cam = (frame * sp) % PERIOD local ic = floor(cam) local ph = floor((cam - ic) * NPH) for j = 0, NCH - 1 do local c = CHUNK[ph * NCH + j + 1] or CHUNK[j + 1] if c then for k = 0, 1 do local x = j * CH_W - ic + k * PERIOD if x < W and x + CH_W > 0 then blit_rgb(c, x, 0, CH_W, SHELF) end end end end local sh = ph / NPH for k = 0, 1 do for i = 1, #ITEMS do local it = ITEMS[i] local x = it[1] - ic - sh + k * PERIOD if x < W + 2 and x + it[2] > -2 then it[4](x) end end end local c3 = (cam * 1.5) % PERIOD for k = 0, 1 do for i = 1, #DASH do local x = DASH[i] * 2 - c3 + k * PERIOD hs(x, x + 6, 50, 1, WOOD_D) hs(x + 9, x + 12, 60, 1, WOOD_D) end end if cfg.eye ~= false then draw_eye() end end