info = { type = "image", title = "Axolotl tank", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "An axolotl strolls along the gravel of a tank", api = 33, } local tr = ({ sk = { ["Axolotl colour"] = "Farba axolotla", ["Pink"] = "Ružový", ["Golden"] = "Zlatý", ["Dark"] = "Tmavý" }, cs = { ["Axolotl colour"] = "Barva axolotla", ["Pink"] = "Růžový", ["Golden"] = "Zlatý", ["Dark"] = "Tmavý" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "tone", label = T("Axolotl colour"), type = "int", default = "pink", opts = { keys = { "pink", "golden", "dark" }, T("Pink"), T("Golden"), T("Dark") } }, } local rect, px, blend = gfx.rect, gfx.px, gfx.blend local floor, sin, max = math.floor, math.sin, math.max local W, H = gfx.W, gfx.H local TAU = 6.28318 local BODY = { [2] = "..fffffffffffffff", [3] = ".fbbbbbbbbbbbbbbb", [4] = "fbbbbbbbbbbbbbbbb", [5] = "fbbbbbbbbbbbbbbbb", [6] = ".fbbbbbbbbbbbbbbb", [7] = "..sllllllllllllll", [8] = "...ssllllllllllll" } local HEAD_SIDE = { [2] = "..bbbbb..", [3] = ".bbbbbbbb", [4] = "bbbbbebbb", [5] = "bbbbbbbbb", [6] = "bbbbbbbbb", [7] = "lllllllm.", [8] = ".llllll.." } local HEAD_FRONT = { [2] = "..bbbbb..", [3] = ".bbbbbbb.", [4] = "bbebbbebb", [5] = "bbbbbbbbb", [6] = "bbbmmmbbb", [7] = ".bbbbbbb.", [8] = "..lllll.." } local CELL = { b = 1, s = 2, l = 3, e = 5, m = 6, f = 7 } local PW, PH = 26, 11 local Y0 = 46 local LEGS = { { 21, 0, 4, 1 }, { 19, 0, 6, 1 }, { 18, 1, 7, 0 }, { 20, 1, 5, 0 } } local TONES = { pink = { b = { 242, 168, 182 }, s = { 206, 122, 148 }, l = { 252, 214, 220 }, e = { 24, 20, 32 }, m = { 186, 88, 118 }, g = { 214, 56, 92 }, gt = { 246, 130, 156 } }, golden = { b = { 240, 196, 96 }, s = { 196, 146, 60 }, l = { 252, 230, 160 }, e = { 24, 20, 32 }, m = { 170, 108, 48 }, g = { 232, 110, 48 }, gt = { 252, 170, 90 } }, dark = { b = { 84, 78, 112 }, s = { 54, 50, 82 }, l = { 118, 112, 146 }, e = { 232, 220, 150 }, m = { 40, 36, 62 }, g = { 168, 66, 96 }, gt = { 214, 110, 136 } }, } local WATER_NOM, GRAVEL_NOM = { 40, 100, 148 }, { 150, 126, 100 } local TN, PAL, PIDX, CACHE = nil, nil, nil, nil local function mixc(a, b, t) return { a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t, a[3] + (b[3] - a[3]) * t } end function on_settings() TN = TONES[cfg.tone] or TONES.pink PAL, PIDX, CACHE = { 0, 0, 0 }, {}, {} end local function col(a, nom) if a == 0 then return nom end if a == 1 then return TN.b elseif a == 2 then return TN.s elseif a == 3 then return TN.l elseif a == 5 then return TN.e elseif a == 6 then return TN.m end return mixc(TN.b, WATER_NOM, 0.3) end local function mix_idx(a, b, q, grav) if a == b then if a == 0 then return 0 end q = 0 end local key = a + b * 16 + q * 256 + (grav and 4096 or 0) local i = PIDX[key] if i then return i end local nom = grav and GRAVEL_NOM or WATER_NOM local c = mixc(col(a, nom), col(b, nom), q / 4) i = #PAL // 3 PAL[#PAL + 1], PAL[#PAL + 2], PAL[#PAL + 3] = floor(c[1] + 0.5), floor(c[2] + 0.5), floor(c[3] + 0.5) PIDX[key] = i return i end local function sprite(phase, front, q) local key = phase * 8 + (front and 4 or 0) + q local s = CACHE[key] if s then return s end local cells = {} local head = front and HEAD_FRONT or HEAD_SIDE for y = 0, PH - 1 do local r = {} local line = BODY[y] and (BODY[y] .. head[y]) or nil for x = 0, PW - 1 do r[x] = line and CELL[line:sub(x + 1, x + 1)] or 0 end cells[y] = r end local L = LEGS[phase + 1] for k = 0, 1 do local lx, lift = L[k * 2 + 1], L[k * 2 + 2] cells[9][lx], cells[9][lx + 1] = 1, 1 if lift == 0 then cells[10][lx], cells[10][lx + 1], cells[10][lx + 2] = 2, 2, 2 end end local rows = {} for y = 0, PH - 1 do local row = {} for x = 0, PW do row[x + 1] = mix_idx(cells[y][x] or 0, x > 0 and cells[y][x - 1] or 0, q, y >= 10) end rows[y + 1] = string.char(table.unpack(row, 1, PW + 1)) end s = table.concat(rows) CACHE[key] = s return s end local BG, STAGE = nil, 0 local function build_bg() if STAGE == 0 then rect(0, 0, W, 2, 26, 36, 52) rect(0, 2, W, 2, 150, 208, 230) for y = 4, 40 do local t = (y - 4) / 36 rect(0, y, W, 1, floor(96 - 56 * t + 0.5), floor(170 - 68 * t + 0.5), floor(208 - 60 * t + 0.5)) end rect(0, 41, W, 15, 40, 102, 148) rect(0, 0, 1, 56, 26, 36, 52); rect(W - 1, 0, 1, 56, 26, 36, 52) for k = 0, 13 do local h = math.hash32(k * 0x9E3779B1) local x, ht = 3 + math.umod(h, 58), 12 + math.umod(h >> 8, 16) rect(x, 56 - ht, 1, ht, 34, 96, 108) if k % 2 == 0 then rect(x + 1, 56 - ht + 4, 1, ht - 4, 30, 88, 104) end end STAGE = 1 return end if STAGE == 1 then rect(26, 53, 9, 3, 92, 104, 118); rect(27, 52, 7, 1, 128, 140, 152); rect(35, 55, 5, 1, 92, 104, 118) rect(52, 49, 7, 7, 60, 82, 96); rect(52, 49, 7, 1, 84, 108, 120); rect(52, 49, 1, 7, 76, 98, 112) for k = 0, 5 do px(53 + k % 2 * 2, 51 + k // 2 * 2, 36, 54, 68) end rect(55, 47, 1, 2, 60, 82, 96) STAGE = 2 return end rect(0, 56, W, 8, 152, 128, 102) rect(0, 56, W, 1, 178, 154, 124) for k = 0, 59 do local h = math.hash32(k * 0x85EBCA6B) local c = ({ { 204, 180, 148 }, { 110, 92, 76 }, { 130, 156, 150 } })[1 + k % 3] px(math.umod(h, W), 57 + math.umod(h >> 8, 7), c[1], c[2], c[3]) end rect(0, 61, W, 3, 128, 106, 86) for k = 0, 22 do local h = math.hash32(k * 0xC2B2AE35) px(math.umod(h, W), 61 + math.umod(h >> 8, 3), 170, 146, 118) end BG = gfx.snapshot(0, 0, W, H) end local MID = { { 14, 22, 2, 1 }, { 17, 16, 2, 2 }, { 45, 20, 2, 1 }, { 48, 24, 2, 2 }, { 40, 14, 1, 2 } } local FRONT = { { 2, 26, 2, 2 }, { 5, 18, 2, 1 }, { 59, 22, 2, 1 }, { 62, 28, 2, 2 }, { 57, 15, 1, 2 } } local BLADE = { { 40, 138, 84 }, { 74, 176, 104 } } local function plants(list, t) for k = 1, #list do local b = list[k] local c = BLADE[b[4]] local sh0 = 0 for j = 1, 4 do local sh = floor(1.6 * sin(t * 0.9 + k * 1.7 + j * 0.5) * j / 4 + 0.5) rect(b[1] + sh, 56 - j * (b[2] // 4), b[3], b[2] // 4 + 1, c[1], c[2], c[3]) end px(b[1], 56 - b[2], 120, 206, 130) end end local BUB = { { 12, 0 }, { 5, 31 }, { 17, 62 }, { 9, 93 }, { 21, 124 }, { 3, 155 }, { 14, 186 } } local function spx(x, y, r, g, b, a) local ix, iy = floor(x), floor(y) local fx, fy = x - ix, y - iy blend(ix, iy, r, g, b, a * (1 - fx) * (1 - fy)); blend(ix + 1, iy, r, g, b, a * fx * (1 - fy)) blend(ix, iy + 1, r, g, b, a * (1 - fx) * fy); blend(ix + 1, iy + 1, r, g, b, a * fx * fy) end local function gill(bx, by, dx, dy, t, ph) for i = 0, 3 do local sw = 0.7 * sin(t * 3.2 + ph + i * 0.7) * i / 3 local x, y = bx + dx * i + sw * -dy, by + dy * i + sw * dx local c = i == 3 and TN.gt or TN.g spx(x, y, c[1], c[2], c[3], 1) end end local V = 7 / 30 local W1, I1, LK, I2, W2, EM = 201, 40, 80, 20, 189, 150 local CYC = W1 + I1 + LK + I2 + W2 + EM function render() if not BG then build_bg() return end if not TN then on_settings() end gfx.blit_rgb(BG, 0, 0, W, H) local f = frame local t = f / 30 plants(MID, t) for k = 1, #BUB do local bb = BUB[k] local age = (f + bb[2]) % 220 local y = 48 - age * 0.21 if y > 4 then local x = 55.5 + 1.2 * sin(age * 0.09 + k) + (k % 3 - 1) * 1.5 spx(x, y, 214, 240, 252, 0.8) end end local a = (f + 90) % CYC local x, moving, front = nil, false, false if a < W1 then x, moving = -27 + a * V, true elseif a < W1 + I1 then x = 20 elseif a < W1 + I1 + LK then x, front = 20, (a - W1 - I1) > 8 and (a - W1 - I1) < LK - 8 elseif a < W1 + I1 + LK + I2 then x = 20 elseif a < CYC - EM then x, moving = 20 + (a - W1 - I1 - LK - I2) * V, true end if x then local ix = floor(x) local q = floor((x - ix) * 4) local phase = moving and floor(x * 0.5) % 4 or 1 local pal_cells = sprite(phase, front, q) gfx.blit_indexed(pal_cells, PAL, ix, Y0, PW + 1, PH, PW + 1, PH, true) local gx = ix + q / 4 if front then gill(gx + 17, Y0 + 3, -1, -0.6, t, 0); gill(gx + 17, Y0 + 4, -1, 0, t, 1.3); gill(gx + 17, Y0 + 5, -1, 0.5, t, 2.6) gill(gx + 26, Y0 + 3, 1, -0.6, t, 0.6); gill(gx + 26, Y0 + 4, 1, 0, t, 1.9); gill(gx + 26, Y0 + 5, 1, 0.5, t, 3.2) else gill(gx + 19, Y0 + 3, -0.7, -0.7, t, 0); gill(gx + 18, Y0 + 4, -1, -0.3, t, 1.3); gill(gx + 18, Y0 + 5, -1, 0.1, t, 2.6) end end plants(FRONT, t + 2) end