info = { type = "image", title = "Snowfall", category = "nature", author = "BRRRO", version = "1.0", license = "MIT", desc = "Snow over a cottage in the hills, day or night", api = 39, } permissions = { "location" } local ltr = ({ sk = { ["Intensity"] = "Intenzita", ["„intense“ = blizzard, „random“ = changes by itself"] = "„silno“ = fujavica, „náhodne“ = mení sa samo", ["random"] = "náhodne", ["weak"] = "slabo", ["medium"] = "stredne", ["intense"] = "silno", ["Time of day"] = "Denná doba", ["night"] = "noc", ["day"] = "deň", ["by time of day"] = "podľa dennej doby", ["House"] = "Domček", ["lit window, someone inside, chimney smoke"] = "svietiace okno, niekto vnútri, dym z komína", ["Trees"] = "Stromy", ["snow slides off a branch now and then"] = "občas sa zosype sneh z vetvy", ["Fox"] = "Líška", ["trots by now and then; the snow fills its tracks"] = "občas pokluše, sneh zasype jeho stopy" }, cs = { ["Intensity"] = "Intenzita", ["„intense“ = blizzard, „random“ = changes by itself"] = "„silně“ = vánice, „náhodně“ = mění se samo", ["random"] = "náhodně", ["weak"] = "slabě", ["medium"] = "středně", ["intense"] = "silně", ["Time of day"] = "Denní doba", ["night"] = "noc", ["day"] = "den", ["by time of day"] = "podle denní doby", ["House"] = "Domeček", ["lit window, someone inside, chimney smoke"] = "svítící okno, někdo uvnitř, kouř z komína", ["Trees"] = "Stromy", ["snow slides off a branch now and then"] = "občas se sesype sníh z větve", ["Fox"] = "Liška", ["trots by now and then; the snow fills its tracks"] = "občas klusá, sníh zasype jeho stopy" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "power", type = "int", default = "medium", label = LT("Intensity"), hint = LT("„intense“ = blizzard, „random“ = changes by itself"), opts = { keys = { "random", "weak", "medium", "intense" }, LT("random"), LT("weak"), LT("medium"), LT("intense") } }, { key = "day", type = "int", default = "auto", label = LT("Time of day"), opts = { keys = { "night", "day", "auto" }, LT("night"), LT("day"), LT("by time of day") } }, { key = "house", type = "bool", default = true, label = LT("House"), hint = LT("lit window, someone inside, chimney smoke") }, { key = "trees", type = "bool", default = true, label = LT("Trees"), hint = LT("snow slides off a branch now and then") }, { key = "fox", type = "bool", default = true, label = LT("Fox"), hint = LT("trots by now and then; the snow fills its tracks") }, } local px, blend, rect, brect = gfx.px, gfx.blend, gfx.rect, gfx.blend_rect local floor, abs, sin, sqrt = math.floor, math.abs, math.sin, math.sqrt local hash32, umod = math.hash32, math.umod local schar, concat, unpack = string.char, table.concat, table.unpack local W, H, FPS = gfx.W, gfx.H, gfx.FPS local PI2 = 6.28318 local GROUND_Y = H - 17 local GLOW_TOP = GROUND_Y - 13 local SKY = { { 22, 34, 112 }, { 58, 138, 236 } } local GLOW = { { 66, 100, 204 }, { 168, 214, 252 } } local HFAR = { { 84, 118, 206 }, { 120, 168, 236 } } local RFAR = { { 162, 198, 255 }, { 214, 236, 255 } } local RFAR2 = { { 118, 152, 230 }, { 164, 202, 248 } } local HNEAR = { { 36, 60, 150 }, { 80, 140, 220 } } local RNEAR = { { 180, 214, 255 }, { 236, 246, 255 } } local RNEA2 = { { 100, 138, 222 }, { 170, 208, 250 } } local PL_HI = { { 134, 184, 255 }, { 206, 232, 255 } } local PL_LO = { { 42, 76, 178 }, { 122, 180, 248 } } local DR_HI = { { 202, 228, 255 }, { 246, 251, 255 } } local TREE = { { 10, 56, 64 }, { 26, 116, 70 } } local TSNOW = { { 172, 208, 255 }, { 238, 247, 255 } } local WALL = { { 52, 22, 34 }, { 138, 70, 42 } } local ROOF = { { 168, 200, 255 }, { 232, 242, 255 } } local WOFF = { { 24, 20, 48 }, { 36, 56, 96 } } local SMOKE = { { 150, 168, 220 }, { 226, 234, 250 } } local FL0 = { { 150, 184, 246 }, { 200, 224, 252 } } local FL1 = { { 196, 220, 255 }, { 232, 242, 255 } } local FL2 = { { 240, 248, 255 }, { 255, 255, 255 } } local PRINT = { { 20, 40, 136 }, { 76, 130, 220 } } local FOX = { { 176, 72, 24 }, { 236, 112, 30 } } local FOXW = { { 178, 200, 242 }, { 246, 248, 252 } } local FOXK = { { 44, 16, 24 }, { 64, 28, 18 } } local WIN_ON, WIN_LO, SIL = { 255, 200, 98 }, { 255, 150, 56 }, { 40, 18, 26 } local FLAKES = { 22, 44, 76 } local SPEED = { 1.5, 2.0, 2.9 } local LVL = { random = 0, weak = 1, medium = 2, intense = 3 } local MAX_FLAKE = 76 local function mixc(ar, ag, ab, br, bg, bb, t) return floor(ar + (br - ar) * t), floor(ag + (bg - ag) * t), floor(ab + (bb - ab) * t) end local function mixp(p, t) local a, b = p[1], p[2] return floor(a[1] + (b[1] - a[1]) * t), floor(a[2] + (b[2] - a[2]) * t), floor(a[3] + (b[3] - a[3]) * t) end local rng = 0xA3C59AC3 local function rnd() rng = (rng ~ (rng << 13)) & 0xFFFFFFFF rng = rng ~ (rng >> 17) rng = (rng ~ (rng << 5)) & 0xFFFFFFFF return rng end local function frnd(a, b) return a + (b - a) * (umod(rnd(), 1000) / 999.0) end local function amb_lerp(v, n, t) if t <= 0 then return v[1] end if t >= n - 1 then return v[n] end local i = floor(t) return v[i + 1] + (v[i + 2] - v[i + 1]) * (t - i) end local a_cur, a_tgt, a_hold = 1.0, 1.0, 0 local function auto_level(opt, n) if opt > 0 and opt <= n then a_cur, a_tgt, a_hold = opt - 1, opt - 1, 0; return a_cur end if a_hold == 0 then local span = n - 1 for i = 1, 8 do local t = umod(rnd(), 1000) / 999.0 * span if abs(t - a_tgt) >= span * 0.30 then a_tgt = t; break end if i == 8 then a_tgt = span - a_tgt end end a_hold = FPS * 25 + umod(rnd(), FPS * 60) end a_hold = a_hold - 1 a_cur = a_cur + (a_tgt - a_cur) * 0.0032 return a_cur end local TF, TN, LF, LN = {}, {}, {}, {} for x = 1, W do local u = x - 1 TF[x] = GROUND_Y - 9 - floor(4.0 * sin(u * 0.075) + 2.0 * sin(u * 0.031 + 1.7) + 0.5) TN[x] = GROUND_Y - 4 - floor(3.0 * sin(u * 0.11 + 2.4) + 0.5) end local function build_lem(top, lem) for x = 1, W do local t = top[x] local a, b = top[x > 1 and x - 1 or 1], top[x < W and x + 1 or W] local d = (a > b and a or b) - 1 if d < t then d = t end if d > t + 1 then d = t + 1 end if d > GROUND_Y - 2 then d = GROUND_Y - 2 end lem[x] = d end end build_lem(TF, LF) build_lem(TN, LN) local DRIFTS = { { H - 11, 0.4, 1, W // 2 - 1, false }, { H - 5, 3.6, W // 3, W - 2, true } } local TREES = { { 27, GROUND_Y - 2, 7 }, { 34, GROUND_Y + 1, 11 }, { 45, GROUND_Y - 1, 8 }, { 57, GROUND_Y + 2, 13 } } local function tree_w(i, h) local q = i / (h - 1); return floor(h * 0.34 * q * q + 0.7) end local function snowy(i, h) return (i > 1 and i % 3 == 0) or i == h - 1 end local TPX, TPY, TPT, TPD = {}, {}, {}, {} for k = 1, #TREES do local cx, base, h = TREES[k][1], TREES[k][2], TREES[k][3] for i = 2, h - 1 do local w = tree_w(i, h) if snowy(i, h) and w > 0 then for s = -1, 1, 2 do local n = #TPX + 1 TPX[n], TPY[n], TPT[n], TPD[n] = cx + s * w, base - h + i, k, s end end end end local HW, HH = 15, 11 local HX, HY = 9, GROUND_Y - HH local WIN_X, WIN_Y, WIN_W = HX + 5, HY + 4, 4 local CH_X, CH_W, CH_TOP = HX + 10, 3, HY - 5 local WCX, WCY = WIN_X + 1.5, WIN_Y + 1.5 local SPX, SPY, NSP = {}, {}, 0 for i = 0, 25 do local hs = hash32(i * 0x9E3779B1 + 0x2545F491) local sy = GROUND_Y + 3 + umod(hs >> 9, H - GROUND_Y - 4) if umod(hs >> 20, 64) < (sy - GROUND_Y) * 3 then NSP = NSP + 1; SPX[NSP], SPY[NSP] = umod(hs, W), sy end end local FOX_W, FOX_H, FOX_FEET = 9, 5, H - 5 local FOX_BODY = { "......3..", "2.....113", "11111112.", ".111111.." } local FOX_LEGS = { "..3...3..", ".3.....3." } local FOX_DIVE = { "2.....", "11....", ".1111.", ".3.111" } local function sprite(art, mirror) local rows, out, w = {}, {}, #art[1] for r = 1, #art do local s = art[r] for c = 1, w do local k = mirror and (w + 1 - c) or c out[c] = (s:byte(k) == 46) and 0 or (s:byte(k) - 48) end rows[r] = schar(unpack(out, 1, w)) end return concat(rows) end local FOX_SPR = {} for m = 0, 1 do for f = 1, 2 do FOX_SPR[m * 2 + f] = sprite({ FOX_BODY[1], FOX_BODY[2], FOX_BODY[3], FOX_BODY[4], FOX_LEGS[f] }, m == 1) end FOX_SPR[5 + m] = sprite(FOX_DIVE, m == 1) end local FOX_PAL = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } local lvl, flake_n = 1.0, 0 local wind, wind_target, wind_next, wind_now = 0.15, 0.15, 0, 0.15 local day_now = 0.0 local seeded, last_frame = false, 0 local SCENE, scene_key = nil, nil local FX, FY, FS, FL, FW, FWS = {}, {}, {}, {}, {}, {} local FLOOR_Y = { GROUND_Y - 1, GROUND_Y + 9, H + 1 } local FLC, CR, CG, CB = { FL0, FL1, FL2 }, {}, {}, {} local NP, P_LIFE = 8, 84 local SMX, SMY, SMA = {}, {}, {} local NPF = 4 local PFX, PFY, PFA = {}, {}, {} local NTR, tr_i = 32, 0 local TRX, TRY, TRB = {}, {}, {} local NSD = 6 local SDX, SDY = {}, {} local cl_on, cl_x, cl_y, cl_vx, cl_vy, cl_tip, cl_back, next_clump = false, 0, 0, 0, 0, 1, 0, 0 local fox_on, fox_x, fox_dir, fox_ph, fox_t, fox_stop, next_fox = false, 0, 1, 0, 0, 0, 0 local wfl, wfl_t, sil_x, sil_dir, next_sil = 0, 0, nil, 1, 0 local function reset_flake(i, anywhere) local l = umod(rnd(), 3) FL[i], FS[i] = l, 0.10 + 0.09 * l + frnd(0.0, 0.05) FW[i], FWS[i] = frnd(0, PI2), frnd(0.02, 0.05) if anywhere then FX[i], FY[i] = frnd(-4, W + 4), frnd(0, FLOOR_Y[l + 1]); return end if frnd(0, W + abs(wind) * GROUND_Y * 1.4) < W then FX[i], FY[i] = frnd(-3, W + 3), frnd(-8, -1) else FX[i] = (wind >= 0) and frnd(-7, -1) or frnd(W + 1, W + 7) FY[i] = frnd(-6, GROUND_Y - 12) end end local function step_flakes() local m = amb_lerp(SPEED, 3, lvl) for i = 1, flake_n do local l = FL[i] FY[i] = FY[i] + FS[i] * m local w = FW[i] + FWS[i] * m if w > PI2 then w = w - PI2 end FW[i] = w FX[i] = FX[i] + (wind_now * (0.6 + 0.4 * l) + 0.22 * sin(w)) * m if FY[i] > FLOOR_Y[l + 1] or FX[i] < -8 or FX[i] > W + 8 then reset_flake(i, false) end end end local function fall(x, y, r, g, b, a, soft) if not soft then blend(x, floor(y + 0.5), r, g, b, a); return end local yi = floor(y) local f = y - yi f = f * f * (3 - 2 * f) if f < 0.06 then blend(x, yi, r, g, b, a) elseif f > 0.94 then blend(x, yi + 1, r, g, b, a) else blend(x, yi, r, g, b, a * sqrt(1 - f)) blend(x, yi + 1, r, g, b, a * sqrt(f)) end end local function draw_flakes(l0, l1, warm) local m = amb_lerp(SPEED, 3, lvl) for i = 1, flake_n do local l = FL[i] local y = FY[i] if l >= l0 and l <= l1 and y > -2 and y < H then local x = floor(FX[i] + 0.5) local r, g, b = CR[l + 1], CG[l + 1], CB[l + 1] if warm then local dx, dy = x - WCX, y - WCY local d = dx * dx + dy * dy if d < 64 then r, g, b = mixc(r, g, b, WIN_ON[1], WIN_ON[2], WIN_ON[3], 0.7 - d / 92) end end local soft = FS[i] * m < 0.55 fall(x, y, r, g, b, 1.0, soft) if l == 2 then fall(x + 1, y, r, g, b, 0.62, soft) end end end end local function step_wind() if frame >= wind_next then local a = 0.30 + 0.13 * lvl local s = ((rnd() & 1) == 1) and 1 or -1 wind_target = s * frnd(0.30 * a, a) if wind_next == 0 then wind = wind_target end wind_next = frame + 15 * FPS + umod(rnd(), 30 * FPS) end wind = wind + (wind_target - wind) * 0.0044 wind_now = wind * (1 + 0.35 * sin(frame * 0.93 / FPS) * sin(frame * 0.25 / FPS + 1.3)) end local function spin_k() local k = (abs(wind_now) - 0.30) * 3 if k <= 0 or lvl <= 1 then return 0 end if k > 1 then k = 1 end return k * ((lvl < 2) and (lvl - 1) or 1) end local function step_spin() for i = 1, NSD do SDX[i] = SDX[i] + wind_now * 4 + 0.3 * sin(frame * 6 / FPS + i) if SDX[i] > W + 3 or SDX[i] < -4 then SDX[i] = (wind_now >= 0) and frnd(-5, -3) or frnd(W, W + 2) SDY[i] = GROUND_Y - 1 + umod(rnd(), 10) end end end local function splat(x, y, r, g, b, a) local xi, yi = floor(x), floor(y) local fx, fy = x - xi, y - yi local w = a * sqrt((1 - fx) * (1 - fy)) if w > 0.15 then blend(xi, yi, r, g, b, w) end w = a * sqrt(fx * (1 - fy)) if w > 0.15 then blend(xi + 1, yi, r, g, b, w) end w = a * sqrt((1 - fx) * fy) if w > 0.15 then blend(xi, yi + 1, r, g, b, w) end w = a * sqrt(fx * fy) if w > 0.15 then blend(xi + 1, yi + 1, r, g, b, w) end end local function step_smoke() for i = 1, NP do local a = SMA[i] if a >= 0 then a = a + 1 SMY[i] = SMY[i] - 0.2 SMX[i] = SMX[i] + wind_now * 0.55 * (a < 24 and a / 24 or 1) + 0.05 * sin(a * 0.15 + i) if a > P_LIFE or SMY[i] < -2 then a = -1 end SMA[i] = a end end if frame % floor(FPS * 0.37) == 0 then for i = 1, NP do if SMA[i] < 0 then SMA[i], SMX[i], SMY[i] = 0, CH_X + 1, CH_TOP - 1; break end end end end local function draw_smoke(dq) local r, g, b = mixp(SMOKE, dq) for i = 1, NP do local a = SMA[i] if a >= 0 then local q = a / P_LIFE local al = 0.8 * (1 - q) if al > 0.15 then splat(SMX[i], SMY[i], r, g, b, al) if q > 0.35 then splat(SMX[i] + 0.8, SMY[i] + 0.5, r, g, b, al * 0.6) end end end end end local function step_window() if frame % floor(FPS * 0.1) == 0 then wfl_t = umod(hash32(frame * 0x9E3779B1), 100) * 0.0045 end wfl = wfl + (wfl_t - wfl) * 0.35 if sil_x then sil_x = sil_x + 0.11 * sil_dir if sil_x < WIN_X - 4 or sil_x > WIN_X + WIN_W + 1 then sil_x, next_sil = nil, frame + 12 * FPS + umod(rnd(), 25 * FPS) end elseif frame >= next_sil then sil_dir = ((rnd() & 1) == 1) and 1 or -1 sil_x = (sil_dir > 0) and (WIN_X - 3) or (WIN_X + WIN_W) end end local function draw_window() local r, g, b = mixc(WIN_ON[1], WIN_ON[2], WIN_ON[3], WIN_LO[1], WIN_LO[2], WIN_LO[3], wfl) rect(WIN_X, WIN_Y, WIN_W, WIN_W, r, g, b) brect(WIN_X - 1, WIN_Y - 1, WIN_W + 2, 1, r, g, b, 0.30) brect(WIN_X - 1, WIN_Y + WIN_W, WIN_W + 2, 1, r, g, b, 0.30) brect(WIN_X - 1, WIN_Y, 1, WIN_W, r, g, b, 0.30) brect(WIN_X + WIN_W, WIN_Y, 1, WIN_W, r, g, b, 0.30) if sil_x then gfx.clip(WIN_X, WIN_Y, WIN_W, WIN_W) local xi = floor(sil_x) local f = sil_x - xi brect(xi, WIN_Y + 1, 1, 3, SIL[1], SIL[2], SIL[3], 1 - f) rect(xi + 1, WIN_Y + 1, 1, 3, SIL[1], SIL[2], SIL[3]) brect(xi + 2, WIN_Y + 1, 1, 3, SIL[1], SIL[2], SIL[3], f) brect(xi + 1, WIN_Y, 1, 1, SIL[1], SIL[2], SIL[3], 1 - f) brect(xi + 2, WIN_Y, 1, 1, SIL[1], SIL[2], SIL[3], f) gfx.clip() end local k = 1 - 0.4 * wfl brect(WIN_X - 2, GROUND_Y, WIN_W + 4, 1, r, g, b, 0.50 * k) brect(WIN_X - 1, GROUND_Y + 1, WIN_W + 2, 1, r, g, b, 0.28 * k) end local function poof(x, y) for i = 1, NPF do if PFA[i] < 0 then PFX[i], PFY[i], PFA[i] = x, y, 0; return end end end local function step_poofs() for i = 1, NPF do if PFA[i] >= 0 then PFA[i] = (PFA[i] < 12) and PFA[i] + 1 or -1 end end end local function draw_poofs(r, g, b) for i = 1, NPF do local a = PFA[i] if a >= 0 then local k, d, x, y = 0.75 * (1 - a / 13), floor(a / 3 + 0.5), PFX[i], PFY[i] blend(x - d, y - 1, r, g, b, k) blend(x + d, y - 1, r, g, b, k) blend(x, y - 1 - floor(a / 4), r, g, b, k) end end end local function step_clump() if cl_on then cl_vy = cl_vy + 0.05 cl_x, cl_y = cl_x + cl_vx + wind_now * 0.25, cl_y + cl_vy cl_vx = cl_vx * 0.9 local land = TREES[TPT[cl_tip]][2] + 1 if cl_y >= land then cl_on = false; poof(floor(cl_x + 0.5), land) end elseif frame >= next_clump then cl_tip = 1 + umod(rnd(), #TPX) cl_on, cl_x, cl_y, cl_vx, cl_vy = true, TPX[cl_tip], TPY[cl_tip], 0.25 * TPD[cl_tip], 0 cl_back = frame + 9 * FPS next_clump = frame + 7 * FPS + umod(rnd(), 14 * FPS) end end local function draw_clump(dq) local sr, sg, sb = mixp(TSNOW, dq) local left = cl_back - frame if left > 0 then local x, y = TPX[cl_tip], TPY[cl_tip] px(x, y, mixp(TREE, dq)) if left < 3 * FPS then blend(x, y, sr, sg, sb, 1 - left / (3 * FPS)) end end if cl_on then fall(floor(cl_x + 0.5), cl_y, sr, sg, sb, 1.0, cl_vy < 0.55) end end local function print_at(x) tr_i = tr_i % NTR + 1 TRX[tr_i], TRY[tr_i], TRB[tr_i] = x, FOX_FEET, frame end local function step_fox() if not fox_on then if frame >= next_fox then fox_on, fox_ph, fox_t = true, 0, 0 fox_dir = ((rnd() & 1) == 1) and 1 or -1 fox_x = (fox_dir > 0) and -FOX_W or W fox_stop = (umod(rnd(), 3) == 0) and -99 or (12 + umod(rnd(), W - 24 - FOX_W)) end return end fox_t = fox_t + 1 if fox_ph == 0 or fox_ph == 4 then fox_x = fox_x + fox_dir if fox_x % 3 == 0 then print_at(fox_x + ((fox_dir > 0) and 2 or FOX_W - 3)) end if fox_ph == 0 and fox_x == fox_stop then fox_ph, fox_t = 1, 0 end if fox_x < -FOX_W - 1 or fox_x > W + 1 then fox_on, next_fox = false, frame + 40 * FPS + umod(rnd(), 60 * FPS) end elseif fox_ph == 1 then if fox_t >= 40 then fox_ph, fox_t = 2, 0 end elseif fox_ph == 2 then fox_x = fox_x + fox_dir if fox_t >= 14 then fox_ph, fox_t = 3, 0 local nx = fox_x + ((fox_dir > 0) and 7 or 1) poof(nx, FOX_FEET) for d = -1, 1 do print_at(nx + d) end end elseif fox_t >= 45 then fox_ph, fox_t = 4, 0 end end local function draw_fox(dq) FOX_PAL[4], FOX_PAL[5], FOX_PAL[6] = mixp(FOX, dq) FOX_PAL[7], FOX_PAL[8], FOX_PAL[9] = mixp(FOXW, dq) FOX_PAL[10], FOX_PAL[11], FOX_PAL[12] = mixp(FOXK, dq) local fr = 1 if fox_ph == 0 or fox_ph == 4 then fr = 1 + (frame * 10 // FPS) % 2 end local spr = FOX_SPR[((fox_dir > 0) and 0 or 2) + fr] local top = FOX_FEET - FOX_H + 1 if fox_ph == 1 then gfx.clip(0, 0, W, FOX_FEET + 1) top = top + 1 elseif fox_ph == 2 then local q = fox_t / 14 top = top - floor(24 * q * (1 - q) + 0.5) elseif fox_ph == 3 then gfx.blit_indexed(FOX_SPR[(fox_dir > 0) and 5 or 6], FOX_PAL, fox_x + ((fox_dir > 0) and 1 or 2), FOX_FEET - 3, 6, 4, 6, 4, true) return end gfx.blit_indexed(spr, FOX_PAL, fox_x, top, FOX_W, FOX_H, FOX_W, FOX_H, true) if fox_ph == 1 then gfx.clip() end end local function draw_tracks(dq) local r, g, b = mixp(PRINT, dq) local life = (24 - 8 * lvl) * FPS for i = 1, NTR do local age = frame - TRB[i] if age >= 0 and age < life then blend(TRX[i], TRY[i], r, g, b, 0.6 * (1 - age / life)) end end end local function draw_hill(top, lem, B, L, M, dq) local br, bg, bb = mixp(B, dq) local lr, lg, lb = mixp(L, dq) local mr, mg, mb = mixp(M, dq) for x = 1, W do local t = top[x] rect(x - 1, t, 1, GROUND_Y - t, br, bg, bb) rect(x - 1, t, 1, lem[x] - t + 1, lr, lg, lb) px(x - 1, lem[x] + 1, mr, mg, mb) end end local function draw_scene(dq) local sr, sg, sb = mixp(SKY, dq) local gr, gg, gb = mixp(GLOW, dq) rect(0, 0, W, GLOW_TOP, sr, sg, sb) local n = GROUND_Y - GLOW_TOP for y = GLOW_TOP, GROUND_Y - 1 do rect(0, y, W, 1, mixc(sr, sg, sb, gr, gg, gb, (y - GLOW_TOP + 1) / n)) end draw_hill(TF, LF, HFAR, RFAR, RFAR2, dq) draw_hill(TN, LN, HNEAR, RNEAR, RNEA2, dq) local hr, hg, hb = mixp(PL_HI, dq) local lr, lg, lb = mixp(PL_LO, dq) n = H - GROUND_Y for y = GROUND_Y, H - 1 do rect(0, y, W, 1, mixc(hr, hg, hb, lr, lg, lb, (y - GROUND_Y) / n)) end local dhr, dhg, dhb = mixp(DR_HI, dq) local shr, shg, shb = mixp(PRINT, dq) for i = 1, #DRIFTS do local d = DRIFTS[i] local a = d[5] and 1.0 or 0.6 for x = d[3], d[4] do local y = d[1] + floor(2.6 * sin(x * 0.11 + d[2]) + 0.5) if y > GROUND_Y + 1 and y < H then blend(x, y, dhr, dhg, dhb, a) if y + 1 < H then blend(x, y + 1, shr, shg, shb, 0.4) end end end end if cfg.trees then local tr, tg, tb = mixp(TREE, dq) local nr, ng, nb = mixp(TSNOW, dq) for k = 1, #TREES do local cx, base, h = TREES[k][1], TREES[k][2], TREES[k][3] for i = 0, h - 1 do local w, y = tree_w(i, h), base - h + i rect(cx - w, y, 2 * w + 1, 1, tr, tg, tb) if snowy(i, h) then px(cx - w, y, nr, ng, nb); px(cx + w, y, nr, ng, nb) end end px(cx, base, tr, tg, tb) end end if cfg.house then local wr, wg, wb = mixp(WALL, dq) local rr, rg, rb = mixp(ROOF, dq) rect(HX, HY, HW, HH, wr, wg, wb) for i = 0, HW // 2 do rect(HX + i, HY - 1 - i, HW - 2 * i, 1, rr, rg, rb) end rect(HX - 1, HY, HW + 2, 1, rr, rg, rb) rect(CH_X, CH_TOP + 1, CH_W, HY - CH_TOP - 1, wr, wg, wb) rect(CH_X, CH_TOP, CH_W, 1, rr, rg, rb) rect(WIN_X, WIN_Y, WIN_W, WIN_W, mixp(WOFF, dq)) end end local function seed() wind, wind_target, wind_next, wind_now = 0.15, 0.15, 0, 0.15 for i = 1, MAX_FLAKE do reset_flake(i, true) end for i = 1, NP do local a = (i - 1) * 11 SMA[i], SMX[i], SMY[i] = a, CH_X + 1 + 0.15 * a * 0.55, CH_TOP - 1 - 0.2 * a end for i = 1, NPF do PFA[i] = -1 end for i = 1, NTR do TRB[i] = -100000 end for i = 1, NSD do SDX[i], SDY[i] = frnd(0, W), GROUND_Y - 1 + umod(rnd(), 10) end a_cur, a_tgt, a_hold = 1.0, 1.0, 0 fox_on, cl_on, sil_x, cl_back = false, false, nil, 0 next_fox = frame + FPS + umod(rnd(), 4 * FPS) next_clump = frame + 3 * FPS + umod(rnd(), 6 * FPS) next_sil = frame + 4 * FPS + umod(rnd(), 8 * FPS) scene_key = nil end local function daylight() local t, s = data.time, data.sun if not (t and t.ok and s) then return 0.0 end if s.polar then return s.up and 1.0 or 0.0 end local h = t.h + t.m / 60.0 local rise, set = s.rise, s.set if h <= rise - 1 or h >= set + 1 then return 0.0 end if h >= rise + 1 and h <= set - 1 then return 1.0 end if h < rise + 1 then return (h - rise + 1) / 2 end return (set + 1 - h) / 2 end local function day_mix() if cfg.day == "night" then return 0.0 end if cfg.day == "day" then return 1.0 end return daylight() end function on_settings() scene_key = nil if not cfg.fox then fox_on = false; for i = 1, NTR do TRB[i] = -100000 end end if not cfg.trees then cl_on, cl_back = false, 0 end if not (cfg.fox or cfg.trees) then for i = 1, NPF do PFA[i] = -1 end end end function update() if not seeded or frame < last_frame then seed(); seeded = true end last_frame = frame day_now = day_mix() lvl = auto_level(LVL[cfg.power] or 2, 3) flake_n = floor(amb_lerp(FLAKES, 3, lvl)) step_wind() step_flakes() step_spin() step_poofs() if cfg.house then step_smoke(); step_window() end if cfg.trees then step_clump() end if cfg.fox then step_fox() end end function render() if not seeded then seed(); seeded = true; day_now = day_mix() end local step = floor(day_now * 8 + 0.5) local dq = step / 8 local key = step + (cfg.house and 16 or 0) + (cfg.trees and 32 or 0) if key ~= scene_key or not SCENE then draw_scene(dq) SCENE = gfx.snapshot(0, 0, W, H) scene_key = key else gfx.blit_rgb(SCENE, 0, 0, W, H) end for l = 1, 3 do CR[l], CG[l], CB[l] = mixp(FLC[l], dq) end local t = frame * 6 // FPS for i = 1, NSP do if umod(hash32(i * 0x9E3779B1 + t * 0x85EBCA6B), 9) == 0 then px(SPX[i], SPY[i], 255, 255, 255) end end local lit = cfg.house and day_now < 0.55 if cfg.house then if lit then draw_window() end draw_smoke(dq) end if cfg.trees then draw_clump(dq) end draw_flakes(0, 1, lit) if cfg.fox then draw_tracks(dq) if fox_on then draw_fox(dq) end end draw_poofs(CR[3], CG[3], CB[3]) draw_flakes(2, 2, lit) local k = spin_k() if k > 0 then for i = 1, NSD do brect(floor(SDX[i]), SDY[i], 3, 1, CR[3], CG[3], CB[3], 0.5 * k) end end end