info = { type = "image", title = "Sprout pot", category = "nature", author = "BRRRO", version = "1.0", license = "MIT", desc = "A sprout grows into a flower in a clay pot", api = 33, } local tr = ({ sk = { ["Petals"] = "Lupene", ["Pot"] = "Kvetináč", ["Water drops"] = "Kvapky vody" }, cs = { ["Petals"] = "Okvětní lístky", ["Pot"] = "Květináč", ["Water drops"] = "Kapky vody" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "petal", label = T("Petals"), type = "color", default = "#FF96BE" }, { key = "pot", label = T("Pot"), type = "color", default = "#C8663F" }, { key = "drops", label = T("Water drops"), type = "int", min = 0, max = 3, default = 3 }, } local px, rect, blend, brect = gfx.px, gfx.rect, gfx.blend, gfx.blend_rect local floor, ceil, sin, cos, sqrt, abs = math.floor, math.ceil, math.sin, math.cos, math.sqrt, math.abs local W, H, FPS = gfx.W, gfx.H, gfx.FPS local TAU = 6.28318 local function mix(a, b, t) return a + (b - a) * t end local function clamp01(v) if v < 0 then return 0 end if v > 1 then return 1 end return v end local function smooth(t) t = clamp01(t); return t * t * (3 - 2 * t) end local CYC = 26 local DROP_T = { 0.67, 8.33, 15.33 } local NDROP = 3 local PETAL = { 255, 150, 190 } local P_L, P_M, P_D, P_DD, P_OUT = {}, {}, {}, {}, {} local NODE_H, NODE_L, NODE_W = { 7, 14, 20 }, { 9, 8, 5 }, { 3.4, 3.2, 2.4 } local SX = 32 local SOIL_Y = 39 local HMAX = 26 local BG = nil local function build_bg() rect(0, 0, W, 58, 246, 230, 190) for x = 0, W - 1, 8 do rect(x, 0, 2, 58, 240, 222, 180) end for y = 3, 36 do local x0 = 4 + (y - 3) * 0.35 rect(floor(x0), y, 22, 1, 255, 248, 218) end for y = 3, 36 do local x0 = 4 + (y - 3) * 0.35 rect(floor(x0 + 10), y, 1, 1, 246, 234, 196) end rect(22, 0, 20, 2, 150, 156, 172) rect(22, 0, 20, 1, 214, 218, 230) rect(22, 2, 20, 1, 96, 102, 122) rect(30, 3, 4, 2, 120, 126, 146) rect(30, 3, 1, 2, 190, 196, 212) rect(30, 4, 4, 1, 80, 86, 106) rect(0, 58, W, 1, 200, 146, 92) rect(0, 59, W, 3, 156, 102, 62) rect(0, 62, W, 2, 128, 82, 52) rect(7, 60, 11, 1, 138, 88, 54); rect(36, 61, 14, 1, 138, 88, 54) brect(19, 58, 26, 2, 60, 30, 20, 0.35) local function col(x) if x < 24 then return P_L end if x < 30 then return P_M end if x < 38 then return P_D end return P_DD end for y = 40, 43 do local c = (y == 40) and P_L or ((y == 43) and P_DD or P_M) rect(17, y, 30, 1, c[1], c[2], c[3]) if y < 43 then rect(17, y, 3, 1, P_L[1], P_L[2], P_L[3]) rect(42, y, 5, 1, P_D[1], P_D[2], P_D[3]) end end for y = 44, 57 do local hw = 12 - (y - 44) * 0.31 local x0, x1 = floor(32 - hw + 0.5), floor(32 + hw - 0.5) for x = x0, x1 do local c = col(x) px(x, y, c[1], c[2], c[3]) end end rect(21, 47, 22, 1, 240, 214, 170) for x = 23, 41, 3 do px(x, 49, 240, 214, 170) end for y = 40, 57 do local hw = (y <= 43) and 15 or (12 - (y - 44) * 0.31) px(floor(32 - hw + 0.5) - 1, y, P_OUT[1], P_OUT[2], P_OUT[3]) px(floor(32 + hw - 0.5) + 1, y, P_OUT[1], P_OUT[2], P_OUT[3]) end rect(17, 39, 30, 1, P_OUT[1], P_OUT[2], P_OUT[3]) rect(24, 58, 16, 1, P_OUT[1], P_OUT[2], P_OUT[3]) rect(24, 37, 16, 1, 74, 46, 34) rect(21, 38, 22, 1, 74, 46, 34) rect(18, 39, 28, 1, 58, 36, 28) for i = 1, 12 do local h = math.hash32(i * 0x9E3779B1) px(20 + math.umod(h, 24), 38 + math.umod(h >> 8, 2), 112, 72, 52) end BG = gfx.snapshot(0, 0, W, H) end local function disc(cx, cy, r, cr, cg, cb) local y0 = floor(cy + 0.5) for j = -floor(r), floor(r) do local hw = sqrt(r * r - j * j) local xl, xr = cx - hw, cx + hw local a, b = floor(xl + 1), floor(xr) if b >= a then rect(a, y0 + j, b - a + 1, 1, cr, cg, cb) end blend(a - 1, y0 + j, cr, cg, cb, a - xl) blend(b + 1, y0 + j, cr, cg, cb, xr - b) end end local function leaf(sx, sy, dir, len, ang, wmax) if len < 1 then return end local c, s = cos(ang), sin(ang) local n = floor(len * c) for k = 0, n do local d = k / c local u = d / len local th = wmax * sin(3.14159 * (u * 0.95 + 0.03)) ^ 0.7 local yc = sy - d * s + 0.05 * d * d local top, bot = yc - th / 2, yc + th / 2 local x = sx + dir * (k + 1) - (dir < 0 and 1 or 0) local it, ib = ceil(top), floor(bot) if ib > it then rect(x, it, 1, ib - it, 86, 178, 60) end blend(x, it - 1, 130, 214, 84, it - top) blend(x, ib, 52, 132, 48, bot - ib) end end local function draw_stem(h) local top = SOIL_Y - h local it = ceil(top) rect(SX, it, 1, SOIL_Y - it + 1, 128, 206, 76) rect(SX + 1, it, 1, SOIL_Y - it + 1, 62, 142, 52) blend(SX, it - 1, 128, 206, 76, it - top) blend(SX + 1, it - 1, 62, 142, 52, it - top) end local function draw_flower(cx, cy, b, t, fall) local R, r = 3.5 * b, 0.6 + 1.2 * b for i = 0, 5 do local ft = fall and (t - fall - i * 0.2) or -1 if ft < 0 then local a = i * TAU / 6 + t * 0.36 local px_, py_ = cx + R * cos(a), cy + R * sin(a) * 0.9 disc(px_, py_, r, PETAL[1], PETAL[2], PETAL[3]) elseif ft < 1.67 then local a = i * TAU / 6 local x = cx + R * cos(a) + 3 * sin(ft * 3.6 + i) local y = cy + R * sin(a) * 0.9 + ft * 16.5 local al = 1 - ft / 1.67 brect(floor(x), floor(y), 2, 1, PETAL[1], PETAL[2], PETAL[3], al) blend(floor(x), floor(y) + 1, PETAL[1], PETAL[2], PETAL[3], al * 0.6) end end end local function draw_butterfly(t) local u = (t - 18.67) / 4.33 if u < 0 or u > 1 then return end local x = 66 - 62 * u + 5 * sin(u * 25) local y = 9 + 7 * sin(3.14159 * u) + 2.5 * sin(u * 31) local f = abs(cos(t * 27)) local yy = floor(y + 0.5) disc(x - 1.7, yy, 0.9 + 1.0 * f, 255, 154, 44) disc(x + 1.7, yy, 0.9 + 1.0 * f, 255, 154, 44) rect(floor(x), yy - 1, 1, 3, 54, 34, 50) end local function draw_drop(t) for i = 1, NDROP do local d = DROP_T[i] local e = t - d if e >= -1 and e < 0 then local r = 0.5 + 1.0 * (1 + e) disc(32, 5 + r, r, 120, 190, 255) elseif e >= 0 and e < 0.8 then local y = 5 + 52.2 * e * e + e * 15 local iy = floor(y) rect(31, iy, 2, 3, 100, 176, 255) px(31, iy, 220, 240, 255) blend(31, iy - 1, 120, 190, 255, 0.5) elseif e >= 0.8 and e < 1.13 then local k = e - 0.8 local sp = 1 + k * 21 blend(floor(32 - sp - 1), SOIL_Y - 1 - (k < 0.133 and 1 or 0), 150, 210, 255, 1 - k * 3) blend(floor(32 + sp + 1), SOIL_Y - 1 - (k < 0.133 and 1 or 0), 150, 210, 255, 1 - k * 3) blend(floor(32 - sp * 0.5), SOIL_Y - 2 - (k < 0.1 and 1 or 0), 200, 230, 255, 1 - k * 3) blend(floor(32 + sp * 0.5), SOIL_Y - 2 - (k < 0.1 and 1 or 0), 200, 230, 255, 1 - k * 3) end if e >= 0.8 and e < 3.67 then brect(20, 38, 24, 2, 30, 16, 12, 0.5 * (1 - (e - 0.8) / 2.87)) end end end local function draw_motes(t) for i = 0, 7 do local x = 8 + (i * 7) % 20 + 3 * sin(t / 3 + i) local y = (6 + i * 5 + t * 0.9 * (1 + i % 3)) % 30 + 4 local a = 0.55 * (0.5 + 0.5 * sin(t * 0.75 + i * 1.7)) local iy = floor(y) local f = y - iy local ix = floor(x) blend(ix, iy, 255, 252, 236, a * (1 - f)) blend(ix, iy + 1, 255, 252, 236, a * f) end end function on_settings() local p = cfg.petal or { r = 255, g = 150, b = 190 } PETAL = { p.r, p.g, p.b } local c = cfg.pot or { r = 200, g = 102, b = 63 } P_L = { mix(c.r, 255, 0.28), mix(c.g, 255, 0.28), mix(c.b, 255, 0.28) } P_M = { c.r, c.g, c.b } P_D = { c.r * 0.78, c.g * 0.74, c.b * 0.74 } P_DD = { c.r * 0.58, c.g * 0.52, c.b * 0.56 } P_OUT = { c.r * 0.4, c.g * 0.32, c.b * 0.34 } NDROP = cfg.drops or 3 BG = nil end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = (frame / FPS + 11) % CYC draw_motes(t) draw_drop(t) local g = smooth((t - 2) / 15.33) local rec = smooth((t - 23.33) / 2) local h = HMAX * g * (1 - rec * rec) if h > 0.3 then draw_stem(h) local sc = 1 - rec for n = 1, 3 do local hn, lmax, wmax = NODE_H[n], NODE_L[n], NODE_W[n] local grow = clamp01((h - hn) / 9) * sc if grow > 0.02 then local open = 1.15 - 0.85 * smooth((t - 2 - n * 1.33) / 6.67) local bob = 0.05 * sin(t * 1.35 + n) local ang = open * (1 - 0.35 * smooth((t - 13.33) / 4)) + bob local y = SOIL_Y - hn leaf(SX, y, -1, lmax * grow, ang, wmax * (0.4 + 0.6 * grow)) leaf(SX + 1, y, 1, lmax * grow, ang + 0.04 * sin(t * 1.5 + 1.3), wmax * (0.4 + 0.6 * grow)) end end local top = SOIL_Y - h if h > HMAX - 3 then local b = smooth((t - 18) / 2.67) local fx, fy = SX + 1 + 0.6 * sin(t * 0.9), top - 1 if b < 0.05 then disc(fx, fy - 1, 1.6 * smooth((h - (HMAX - 3)) / 3), 98, 176, 66) else local cap = 1 - clamp01((t - 23) / 0.67) local fall = (t >= 21.67) and 21.67 or nil draw_flower(fx, fy, b, t, fall) if cap > 0 then disc(fx, fy, 2.1 * b * cap, 255, 206, 70) px(floor(fx), floor(fy) - 1, 255, 240, 160) end end end end draw_butterfly(t) end