info = { type = "image", title = "Blooming pot", category = "nature", author = "BRRRO", version = "1.0", license = "MIT", desc = "A potted plant opens its blooms in the breeze", api = 33, } local tr = ({ sk = { ["Bloom colour"] = "Farba kvetu", ["Breeze"] = "Vánok", ["Bee"] = "Včela" }, cs = { ["Bloom colour"] = "Barva květu", ["Breeze"] = "Vánek", ["Bee"] = "Včela" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "bloom", label = T("Bloom colour"), type = "color", default = "#FF6FA8" }, { key = "breeze", label = T("Breeze"), type = "int", min = 1, max = 3, default = 2 }, { key = "visitor", label = T("Bee"), type = "bool", default = true }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, cos, sqrt, min, max = math.floor, math.sin, math.cos, math.sqrt, math.min, math.max local W, H, FPS = gfx.W, gfx.H, gfx.FPS local TAU = 6.28318 local WALL, BASEBD = { 238, 224, 192 }, { 208, 180, 136 } local FRAME, SKY = { 252, 250, 244 }, { 146, 202, 246 } local SILL, SILL_L = { 196, 164, 120 }, { 224, 196, 150 } local WOOD, WOOD_L = { 140, 92, 52 }, { 184, 130, 78 } local POT, POT_RIM = { 198, 94, 54 }, { 230, 130, 80 } local POT_SH, POT_BAND= { 156, 66, 40 }, { 252, 214, 170 } local SOIL = { 70, 44, 30 } local LEAF, LEAF_L = { 40, 132, 62 }, { 98, 192, 92 } local STEM = { 52, 150, 70 } local CENTER = { 255, 214, 60 } local PETAL, PETAL_L, PETAL_D = { 255, 111, 168 }, { 255, 170, 204 }, { 214, 70, 124 } local BEE, BEE_D = { 255, 210, 40 }, { 40, 30, 20 } local BOOK = { { 190, 60, 60 }, { 60, 100, 180 }, { 226, 190, 70 }, { 70, 150, 100 } } local function c3(c) return c[1], c[2], c[3] end local function soft(x, y, w, h, c) local r, g, b = c[1], c[2], c[3] local x0 = floor(x) local f = x - x0 if f < 0.05 then rect(x0, y, w, h, r, g, b) return end if f > 0.95 then rect(x0 + 1, y, w, h, r, g, b) return end if w > 1 then rect(x0 + 1, y, w - 1, h, r, g, b) end blend_rect(x0, y, 1, h, r, g, b, 1 - f) blend_rect(x0 + w, y, 1, h, r, g, b, f) end local BG = nil local function build_bg() rect(0, 0, W, H, c3(WALL)) rect(6, 2, 52, 44, c3(FRAME)) rect(8, 4, 23, 20, c3(SKY)); rect(33, 4, 23, 20, c3(SKY)) rect(8, 26, 23, 18, c3(SKY)); rect(33, 26, 23, 18, c3(SKY)) rect(4, 46, 56, 2, c3(SILL)); rect(4, 46, 56, 1, c3(SILL_L)) rect(0, 58, W, 6, c3(BASEBD)) rect(0, 55, W, 3, c3(WOOD)); rect(0, 55, W, 1, c3(WOOD_L)) local bx, bh = 2, { 7, 6, 8, 5 } for i = 1, 4 do rect(bx, 55 - bh[i], 3, bh[i], c3(BOOK[i])) rect(bx, 55 - bh[i] + 2, 3, 1, c3(WALL)) bx = bx + 3 end rect(53, 50, 7, 5, c3(POT)); rect(52, 49, 9, 2, c3(POT_RIM)) rect(54, 44, 2, 5, c3(LEAF)); rect(57, 45, 2, 4, c3(LEAF)); rect(55, 42, 1, 3, c3(LEAF_L)) rect(22, 43, 21, 3, c3(POT_RIM)) rect(24, 43, 17, 1, c3(SOIL)) for y = 46, 54 do local half = 9 - (y - 46) // 3 rect(32 - half, y, 2 * half + 1, 1, c3(POT)) rect(32 + half - 2, y, 3, 1, c3(POT_SH)) end rect(23, 49, 19, 1, c3(POT_BAND)) BG = gfx.snapshot(0, 0, W, H) end local STEMS = { { bx = 31, tx = 19, ty = 15 }, { bx = 32, tx = 33, ty = 8 }, { bx = 33, tx = 46, ty = 18 }, } local PHASE = { 0.0, 0.37, 0.71 } local BASE_Y = 43 local function leaf(bx, by, tx, ty, arc, th) local dx = tx - bx local n = max(2, (math.abs(dx) + 2) // 3) local function ypos(u) return by + (ty - by) * u - arc * sin(3.14159 * u) end for i = 0, n - 1 do local xa, xb = floor(bx + dx * i / n), floor(bx + dx * (i + 1) / n) local s = sin(3.14159 * (i + 0.5) / n) local h = max(1, floor(th * sqrt(s) + 0.5)) local ya, yb = ypos(i / n), ypos((i + 1) / n) local x, w = min(xa, xb), max(1, math.abs(xb - xa)) local yt = floor(min(ya, yb) - h / 2 + 0.5) rect(x, yt, w, floor(math.abs(yb - ya) + 0.5) + h, c3(LEAF)) if h >= 2 then rect(x, yt, w, 1, c3(LEAF_L)) end end end local function flower(x, y, stage) if stage == 0 then soft(x - 1, y - 1, 3, 4, PETAL_D) soft(x, y - 2, 1, 1, PETAL_D) soft(x - 1, y + 3, 3, 1, LEAF) elseif stage == 1 then soft(x - 3, y - 1, 2, 2, PETAL); soft(x + 1, y - 1, 2, 2, PETAL) soft(x - 1, y - 3, 2, 2, PETAL); soft(x - 1, y + 1, 2, 2, PETAL) soft(x - 1, y - 1, 2, 2, CENTER) else soft(x - 4, y - 1, 3, 3, PETAL); soft(x + 2, y - 1, 3, 3, PETAL) soft(x - 1, y - 4, 3, 3, PETAL); soft(x - 1, y + 2, 3, 3, PETAL) soft(x - 3, y - 3, 2, 2, PETAL_L); soft(x + 2, y - 3, 2, 2, PETAL_L) soft(x - 3, y + 2, 2, 2, PETAL_L); soft(x + 2, y + 2, 2, 2, PETAL_L) soft(x - 1, y - 1, 3, 3, CENTER) if stage == 3 then soft(x - 5, y, 1, 1, PETAL_L); soft(x + 5, y, 1, 1, PETAL_L) soft(x, y - 5, 1, 1, PETAL_L); soft(x, y + 4, 1, 1, PETAL_L) end end end local fx, fy, fs = {}, {}, {} local CLOUDS = { { 10, 14, 2.2, 8 }, { 30, 12, -1.5, 40 } } local FALL = { { 0, 3.6, 0.0 }, { 1, 4.4, 0.45 }, { 2, 5.2, 0.8 } } function on_settings() local c = cfg.bloom or { r = 255, g = 111, b = 168 } PETAL[1], PETAL[2], PETAL[3] = c.r, c.g, c.b PETAL_L[1], PETAL_L[2], PETAL_L[3] = min(255, c.r + 60), min(255, c.g + 60), min(255, c.b + 40) PETAL_D[1], PETAL_D[2], PETAL_D[3] = c.r * 8 // 10, c.g * 6 // 10, c.b * 7 // 10 end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame local br = cfg.breeze or 2 gfx.clip(8, 4, 48, 40) for i = 1, #CLOUDS do local c = CLOUDS[i] local y, L = c[1], c[2] local x = floor((c[4] + t * c[3] / FPS) % (W + L) - L + 0.5) blend_rect(x + 3, y, L - 6, 1, 255, 255, 255, 0.85) blend_rect(x, y + 1, L, 2, 255, 255, 255, 0.85) blend_rect(x + 2, y + 3, L - 6, 1, 255, 255, 255, 0.6) end gfx.clip() local lw = floor(1.2 * sin(t * TAU / (3.1 * FPS)) * br / 2 + 0.5) leaf(29, BASE_Y, 5, 38 + lw, 9, 4) leaf(28, BASE_Y, 13, 47 - lw, 5, 3) leaf(36, BASE_Y, 59, 38 + lw, 9, 4) leaf(37, BASE_Y, 51, 47 - lw, 5, 3) for i = 1, 3 do local s = STEMS[i] local sw = br * (0.9 * sin(t * TAU / (4.2 * FPS) + i * 0.7) + 0.5 * sin(t * TAU / (2.3 * FPS) + i * 1.9)) * 0.9 local span = BASE_Y - s.ty local y = BASE_Y - 3 while y >= s.ty do local u = (BASE_Y - y) / span soft(s.bx + (s.tx - s.bx) * u ^ 1.5 + sw * u * u - 1, y, 2, 3, STEM) y = y - 3 end fx[i] = s.tx + sw fy[i] = s.ty local o = 0.5 + 0.5 * sin(TAU * (t / (14 * FPS) + PHASE[i])) fs[i] = o < 0.18 and 0 or o < 0.42 and 1 or o < 0.8 and 2 or 3 end for i = 1, 3 do flower(fx[i] - 1 + 0.5, fy[i], fs[i]) end for i = 1, 3 do local f = FALL[i] local u = (t / (f[2] * FPS) + f[3]) % 1 if fs[f[1] + 1] >= 2 then local x = floor(fx[f[1] + 1] + 4 * sin(u * 9 + f[1]) + 0.5) local yf = fy[f[1] + 1] + 4 + u * (BASE_Y + 8 - fy[f[1] + 1]) local py = floor(yf) local fr = yf - py local pc = PETAL_L blend_rect(x, py, 2, 1, pc[1], pc[2], pc[3], 1 - fr) blend_rect(x, py + 1, 2, 1, pc[1], pc[2], pc[3], fr) end end if cfg.visitor ~= false then local a = t * TAU / (9 * FPS) local bx, by = 32 + 23 * cos(a), 25 + 12 * sin(a * 2) local iy = floor(by + 0.5) soft(bx - 1, iy, 3, 2, BEE) px(floor(bx + 0.5), iy, c3(BEE_D)) local up = floor(t * 15 / FPS) % 2 == 0 blend_rect(floor(bx + 0.5) - 1, iy - (up and 2 or 1), 2, 1, 255, 255, 255, 0.85) end end