info = { type = "image", title = "Torii lake", category = "nature", author = "BRRRO", version = "1.0", license = "MIT", desc = "Torii gate at night, swaying lanterns, leaves", api = 33, } local tr = ({ sk = { ["Lanterns"] = "Lampióny", ["Warm"] = "Teplé", ["Red"] = "Červené", ["Pale"] = "Bledé", ["Leaves"] = "Listy" }, cs = { ["Lanterns"] = "Lampióny", ["Warm"] = "Teplé", ["Red"] = "Červené", ["Pale"] = "Bledé", ["Leaves"] = "Listy" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "lamp", label = T("Lanterns"), type = "int", default = 0, opts = { T("Warm"), T("Red"), T("Pale") } }, { key = "leaves", label = T("Leaves"), type = "int", min = 0, max = 12, default = 7 }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, sin, cos, sqrt = math.floor, math.sin, math.cos, math.sqrt local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local TAU = 6.28318 local SIL = { 12, 10, 30 } local SKY0, SKY1 = { 14, 18, 52 }, { 70, 64, 122 } local WAT0, WAT1 = { 44, 44, 96 }, { 14, 18, 48 } local MOON, MOON_D = { 238, 228, 196 }, { 204, 194, 160 } local RING1, RING2 = { 62, 70, 130 }, { 46, 52, 106 } local LAMPS = { { 255, 176, 72 }, { 255, 84, 64 }, { 226, 236, 214 } } local LEAF = { { 226, 92, 42 }, { 244, 150, 48 }, { 190, 52, 40 } } local WY, BASE = 40, 44 local PX1, PX2 = 26, 46 local function lerp(a, b, t) return floor(a + (b - a) * t + 0.5) end local function mix(c0, c1, t) return lerp(c0[1], c1[1], t), lerp(c0[2], c1[2], t), lerp(c0[3], c1[3], t) end local function fbox(x, y, w, h, r, g, b) local ix = floor(x) local f = x - ix if f < 0.04 then rect(ix, y, w, h, r, g, b); return end rect(ix + 1, y, w - 1, h, r, g, b) blend_rect(ix, y, 1, h, r, g, b, 1 - f) blend_rect(ix + w, y, 1, h, r, g, b, f) end local function fblend(x, y, w, h, r, g, b, a) local ix = floor(x) local f = x - ix blend_rect(ix + 1, y, w - 1, h, r, g, b, a) blend_rect(ix, y, 1, h, r, g, b, a * (1 - f)) blend_rect(ix + w, y, 1, h, r, g, b, a * f) end local BG local WROW, REFC = {}, {} local STARS = {} local function ridge(x) return floor(35 + 1.6 * sin(x * 0.13) + 1.2 * sin(x * 0.37 + 1) + 0.5) end local function pine(x, y, h) rect(x, y - 1, 1, 2, SIL[1], SIL[2], SIL[3]) for i = 0, h - 1 do local w = 1 + 2 * (i // 2) rect(x - w // 2, y - h + i, w, 1, SIL[1], SIL[2], SIL[3]) end end local function build_bg() for y = 0, WY - 1 do local t = (y / (WY - 1)) ^ 1.2 rect(0, y, W, 1, mix(SKY0, SKY1, t)) end for y = WY, H - 1 do local t = (y - WY) / (H - 1 - WY) WROW[y] = { mix(WAT0, WAT1, t ^ 0.7) } rect(0, y, W, 1, WROW[y][1], WROW[y][2], WROW[y][3]) end for dy = 1, H - 1 - BASE do local w = WROW[BASE + dy] local t = 0.1 + 0.7 * dy / (H - BASE) REFC[dy] = { lerp(SIL[1], w[1], t), lerp(SIL[2], w[2], t), lerp(SIL[3], w[3], t) } end local MX, MY, MR = 13, 13, 5 for y = MY - 10, MY + 10 do for x = MX - 10, MX + 10 do local d = sqrt((x - MX) ^ 2 + (y - MY) ^ 2) if d <= MR + 0.5 then px(x, y, MOON[1], MOON[2], MOON[3]) elseif d <= MR + 2.5 then px(x, y, RING1[1], RING1[2], RING1[3]) elseif d <= MR + 4.5 then px(x, y, RING2[1], RING2[2], RING2[3]) end end end px(MX - 2, MY - 1, MOON_D[1], MOON_D[2], MOON_D[3]); px(MX - 1, MY - 1, MOON_D[1], MOON_D[2], MOON_D[3]) px(MX + 2, MY + 1, MOON_D[1], MOON_D[2], MOON_D[3]); px(MX, MY + 3, MOON_D[1], MOON_D[2], MOON_D[3]) for x = 0, W - 1 do local top = ridge(x) rect(x, top, 1, WY - top, SIL[1], SIL[2], SIL[3]) blend_rect(x, WY, 1, WY - top > 5 and 5 or WY - top, SIL[1], SIL[2], SIL[3], 0.55) end pine(3, WY - 1, 8); pine(8, WY - 1, 6); pine(12, WY - 1, 9); pine(58, WY - 1, 7); pine(62, WY - 1, 5) local S = SIL rect(18, 8, 4, 2, S[1], S[2], S[3]); rect(54, 8, 4, 2, S[1], S[2], S[3]) rect(20, 9, 36, 3, S[1], S[2], S[3]); rect(22, 12, 32, 2, S[1], S[2], S[3]) rect(24, 19, 28, 2, S[1], S[2], S[3]) rect(36, 14, 4, 5, S[1], S[2], S[3]) rect(PX1, 14, 4, BASE - 14, S[1], S[2], S[3]); rect(PX2, 14, 4, BASE - 14, S[1], S[2], S[3]) rect(PX1 - 1, BASE - 8, 6, 8, S[1], S[2], S[3]); rect(PX2 - 1, BASE - 8, 6, 8, S[1], S[2], S[3]) local k, i = 0, 0 while k < 14 and i < 100 do i = i + 1 local h = hash32(i * 0x9E3779B1) local x, y = umod(h, W), umod(h >> 8, 28) if (x - MX) ^ 2 + (y - MY) ^ 2 > 120 and (x < 17 or x > 59 or y < 6) then k = k + 1 STARS[k] = { x, y, umod(h >> 16, 628) / 100 } end end BG = gfx.snapshot(0, 0, W, H) end local LANT = { { 35, 22, 7, 2.4, 0.3 }, { 41, 22, 9, 2.8, 2.2 }, { 55, 14, 6, 2.1, 4.1 } } local function lantern(L, t, lc) local hx, hy, r, per, ph = L[1], L[2], L[3], L[4], L[5] local gust = 0.65 + 0.35 * sin(t * TAU / 17 + ph) local th = 0.3 * gust * sin(t * TAU / per + ph) local s, c = sin(th), cos(th) local rx, ry = hx + r * s, hy + r * c local tn = s / c for y = hy, floor(ry) - 1 do local x = hx + (y - hy + 0.5) * tn local ix = floor(x) local f = x - ix blend(ix, y, SIL[1], SIL[2], SIL[3], 1 - f) blend(ix + 1, y, SIL[1], SIL[2], SIL[3], f) end local top = floor(ry + 0.5) local lx = rx - 1.5 fbox(lx - 0.5, top, 5, 1, SIL[1], SIL[2], SIL[3]) fbox(lx, top + 1, 4, 5, lc[1], lc[2], lc[3]) fbox(lx + 1, top + 2, 2, 2, 255, 244, 200) fbox(lx, top + 6, 4, 1, SIL[1], SIL[2], SIL[3]) local fl = 0.5 + 0.2 * sin(t * 5.1 + ph * 3) local ref = BASE + (BASE - top) - 3 if ref > WY + 2 and ref < H - 3 then for k = 0, 2 do local oy = ref + k * 2 if oy < H then local ox = 0.6 * sin(t * 2.3 + k * 1.7 + ph) fblend(lx + ox - k * 0.5 + 0.5 * k, oy, 4 - k, 1, lc[1], lc[2], lc[3], fl * (1 - k * 0.25)) end end end end local LEAFN = 12 local LV = {} for i = 1, LEAFN do local h = hash32(i * 0x85EBCA6B) LV[i] = { x0 = 4 + umod(h, 54), v = 6 + umod(h >> 6, 5), ph = umod(h >> 10, 628) / 100, yl = 47 + umod(h >> 14, 14), off = umod(h >> 18, 2000) / 100, col = umod(h >> 26, 3) + 1, sw = 2 + umod(h >> 22, 3), } end local function leaf(v, t) local tf = (v.yl + 3) / v.v local cyc = tf + 2.2 local u = (t + v.off) % cyc local x, y, a if u < tf then y = -3 + v.v * u x = v.x0 + v.sw * sin(u * 1.7 + v.ph) a = 1 else y = v.yl x = v.x0 + v.sw * sin(tf * 1.7 + v.ph) + (u - tf) * 0.6 a = 1 - (u - tf) / 2.2 end local c = LEAF[v.col] local iy = floor(y) local fy = y - iy if a < 1 then fblend(x, iy, 3, 1, c[1], c[2], c[3], a * 0.9) return end fblend(x, iy, 2, 1, c[1], c[2], c[3], 1 - fy) fblend(x, iy + 1, 2, 1, c[1], c[2], c[3], 1) fblend(x, iy + 2, 2, 1, c[1], c[2], c[3], fy) end local CLOUD_C = { 70, 72, 138 } function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame / FPS for i = 1, #STARS do local s = STARS[i] blend(s[1], s[2], 220, 224, 255, 0.3 + 0.4 * sin(t * 1.3 + s[3])) end local cx = (t * 1.6) % 90 - 26 fblend(cx + 3, 12, 14, 1, CLOUD_C[1], CLOUD_C[2], CLOUD_C[3], 0.4) fblend(cx, 13, 20, 2, CLOUD_C[1], CLOUD_C[2], CLOUD_C[3], 0.4) for dy = 1, H - 1 - BASE do local y = BASE + dy local ox = (0.3 + dy * 0.07) * sin(dy * 0.85 - t * 2.4) local c = REFC[dy] fbox(PX1 + ox, y, 4, 1, c[1], c[2], c[3]) fbox(PX2 + ox * 0.9, y, 4, 1, c[1], c[2], c[3]) end for k = 0, 10 do local y = WY + 3 + k * 2 local w = 1 + k // 2 local x = 13 - w / 2 + 1.2 * sin(t * 1.9 + k * 1.3) fblend(x, y, w, 1, MOON[1], MOON[2], MOON[3], 0.28 + 0.2 * sin(t * 2.7 + k)) end for k = 1, 7 do local h = hash32(k * 0x2545F491) local y = WY + 3 + umod(h, 20) local x = (umod(h >> 8, 80) + t * (0.5 + umod(h >> 16, 6) / 10)) % 80 - 8 fblend(x, y, 4 + umod(h >> 20, 5), 1, 120, 124, 190, 0.2) end local lc = LAMPS[(cfg.lamp or 0) + 1] or LAMPS[1] for i = 1, 3 do lantern(LANT[i], t, lc) end for i = 1, cfg.leaves or 7 do leaf(LV[i], t) end end