info = { type = "image", title = "Skate cabin", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A skater crosses the frozen lake past a cabin", api = 33, } local tr = ({ sk = { ["Jacket"] = "Bunda", ["Snow"] = "Sneh", ["Speed"] = "Rýchlosť" }, cs = { ["Jacket"] = "Bunda", ["Snow"] = "Sníh", ["Speed"] = "Rychlost" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "jacket", label = T("Jacket"), type = "color", default = "#5468D6" }, { key = "snow", label = T("Snow"), type = "int", min = 0, max = 14, default = 8 }, { key = "speed", label = T("Speed"), type = "int", min = 1, max = 5, default = 3 }, } local rect, px, blend_rect, blend = gfx.rect, gfx.px, gfx.blend_rect, gfx.blend local blit_rgb, snapshot = gfx.blit_rgb, gfx.snapshot local floor, sin, cos, min, max = math.floor, math.sin, math.cos, math.min, math.max local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local SKY_T, SKY_B = { 176, 160, 246 }, { 255, 212, 230 } local HILL_F, HILL_N = { 238, 214, 242 }, { 252, 234, 248 } local ICE_T, ICE_B = { 150, 208, 240 }, { 204, 240, 252 } local SNOW, SNOW_SH = { 255, 240, 252 }, { 248, 204, 232 } local EAVE, LOG_L, LOG_D, LOG_E = { 120, 80, 96 }, { 190, 132, 120 }, { 164, 106, 98 }, { 130, 84, 84 } local FRAME, GLASS, GLASS_L = { 96, 60, 74 }, { 255, 178, 220 }, { 255, 214, 238 } local PINE_A, PINE_B, PINE_S = { 74, 164, 196 }, { 52, 128, 170 }, { 236, 248, 255 } local function mix(a, b, t) return floor(a[1] + (b[1] - a[1]) * t + 0.5), floor(a[2] + (b[2] - a[2]) * t + 0.5), floor(a[3] + (b[3] - a[3]) * t + 0.5) end local function c3(c) return c[1], c[2], c[3] end local function runs(rows, keys) local out = {} for y, row in ipairs(rows) do local x, last = 1, -1 while x <= #row do local c = row:sub(x, x) local e = x while row:sub(e + 1, e + 1) == c do e = e + 1 end local k = keys:find(c, 1, true) if k > 1 then out[#out + 1] = { x - 1, y - 1, e - x + 1, k - 1, last == x - 1 } end last, x = k > 1 and e or -1, e + 1 end end return out end local function draw(sp, pal, X, Y) local x0 = floor(X) local f = X - x0 if f > 0.88 then x0, f = x0 + 1, 0 end for i = #sp, 1, -1 do local s = sp[i] local r, g, b = c3(pal[s[4]]) local x, y, n = x0 + s[1], Y + s[2], s[3] if f < 0.12 then rect(x, y, n, 1, r, g, b) elseif s[5] then rect(x, y, n, 1, r, g, b) blend_rect(x + n, y, 1, 1, r, g, b, f) else blend_rect(x, y, 1, 1, r, g, b, 1 - f) if n > 1 then rect(x + 1, y, n - 1, 1, r, g, b) end blend_rect(x + n, y, 1, 1, r, g, b, f) end end end local HEAD = { "....pp......", "...hhhh.....", "..hhhhhh....", "..hhhsss....", "...sssse....", "...ssssss...", "..ffffff....", } local ARMS = { { ".aajjjjjaa..", "a..jjjjj..a.", "...jjjjj....", "...jjjjj...." }, { "..ajjjjjaaa.", ".aajjjjj....", "a..jjjjj....", "...jjjjj...." }, } local LEGS = { { "...kkkkk....", "...kk.kk....", "...kk.kk....", "..bbb.bbb...", "..lll.lll..." }, { "...kkkkk....", "..kk..kk....", ".kk....kk...", "bbb.....bbb.", "lll.....lll." }, { "...kkkkk....", ".kkkk.kk....", "bbb...kk....", "......bbb...", "......lll..." }, { "...kkkkk....", "...kk.kkk...", "..kk...kk...", ".bbb....bbb.", ".lll....lll." }, } local KEYS = ".hpsefjakbl" local PAL = { { 255, 112, 160 }, { 255, 244, 200 }, { 255, 218, 196 }, { 60, 50, 90 }, { 255, 226, 130 }, { 84, 104, 214 }, { 64, 82, 176 }, { 58, 64, 140 }, { 250, 250, 255 }, { 110, 116, 170 } } local POSES = {} local function pose(a, l, lean) local key = a * 100 + l * 10 + lean + 1 if not POSES[key] then local rows = {} for i = 1, 11 do local r = i <= 7 and HEAD[i] or ARMS[a][i - 7] rows[i] = ("."):rep(1 + lean) .. r .. ("."):rep(1 - lean) end for i = 1, 5 do rows[11 + i] = "." .. LEGS[l][i] .. "." end POSES[key] = runs(rows, KEYS) end return POSES[key] end function on_settings() local j = cfg.jacket or { r = 84, g = 104, b = 214 } PAL[6] = { j.r, j.g, j.b } PAL[7] = { j.r * 3 // 4, j.g * 3 // 4, j.b * 3 // 4 } end local BG local function pine(x, base, h) local th = h // 3 + 1 for r = 0, h - 1 do local hw = floor((r % th) * 0.7) + r // th * 2 rect(x - hw, base - h + r, hw + 1, 1, c3(PINE_A)) rect(x + 1, base - h + r, hw, 1, c3(PINE_B)) if r % th == th - 1 then px(x - hw, base - h + r, c3(PINE_S)) end end rect(x, base, 2, 2, 110, 74, 84) end local function bake() for y = 0, 33 do rect(0, y, W, 1, mix(SKY_T, SKY_B, y / 33)) end for x = 0, W - 1 do local y1 = floor(25 + 2.5 * sin(x * 0.09 + 1) + 1.5 * sin(x * 0.23)) local y2 = floor(29 + 1.6 * sin(x * 0.13 + 2.2) + sin(x * 0.31)) rect(x, y1, 1, 34 - y1, c3(HILL_F)) rect(x, y2, 1, 34 - y2, c3(HILL_N)) end for y = 34, H - 1 do rect(0, y, W, 1, mix(ICE_T, ICE_B, (y - 34) / 29)) end for i = 1, 20 do local h = hash32(i * 0x9E3779B1) local y, len, x = 36 + umod(h, 22), 3 + umod(h >> 8, 6), umod(h >> 12, W) if i % 3 == 0 then rect(x, y, len, 1, 126, 190, 230) else blend_rect(x, y, len, 1, 255, 255, 255, 0.45) end end rect(40, 32, 24, 2, c3(SNOW)) pine(53, 31, 16) pine(60, 32, 12) pine(46, 30, 8) rect(21, 7, 5, 1, c3(SNOW)) rect(22, 8, 3, 5, 176, 146, 168) local roof = { { 8, 27 }, { 6, 29 }, { 4, 31 }, { 3, 32 }, { 2, 33 } } for i, r in ipairs(roof) do rect(r[1], 10 + i, r[2] - r[1] + 1, 1, c3(i <= 2 and SNOW or SNOW_SH)) end rect(2, 16, 32, 1, c3(EAVE)) for x = 4, 31, 3 do px(x, 17, c3(SNOW_SH)) end for y = 17, 31 do rect(4, y, 28, 1, c3(y % 2 == 1 and LOG_L or LOG_D)) end rect(4, 17, 1, 15, c3(LOG_E)); rect(31, 17, 1, 15, c3(LOG_E)) for _, wx in ipairs({ 7, 16 }) do rect(wx - 1, 20, 9, 7, c3(FRAME)) rect(wx, 21, 7, 5, c3(GLASS)) rect(wx, 21, 7, 1, c3(GLASS_L)) rect(wx + 3, 21, 1, 5, c3(FRAME)); rect(wx, 23, 7, 1, c3(FRAME)) rect(wx - 1, 27, 9, 1, c3(SNOW)) end rect(24, 20, 7, 12, c3(FRAME)) rect(25, 21, 5, 11, 118, 72, 74) px(28, 26, 255, 214, 150) rect(2, 31, 32, 2, c3(SNOW)) rect(0, 33, W, 1, c3(SNOW)) for x = 0, W - 1 do local top = 60 + floor(1.5 * sin(x * 0.17) + 0.5) rect(x, top, 1, H - top, 252, 236, 248) px(x, top, 226, 212, 244) end BG = snapshot(0, 0, W, H) end local CYC, TC, SX0, FADE = 420, 330, -16, 100 local V = (W + 16 + 2) / TC local SPD = { 0.5, 0.75, 1, 1.3, 1.7 } local START = 100 local function lane(cx) return 50 + 4 * sin(cx * 0.105 + 0.6) end local PF = {} for i = 1, 14 do local h = hash32(i * 0x85EBCA6B) PF[i] = { x = umod(h, W), y0 = umod(h >> 6, 70), v = 0.15 + umod(h >> 12, 8) * 0.02, sw = 1.5 + umod(h >> 16, 3), ph = umod(h >> 20, 628) / 100 } end local SM = {} for i = 1, 4 do local h = hash32(i * 0xC2B2AE35) SM[i] = { off = umod(h, 220), w = 3 + umod(h >> 8, 3) } end local function puff(p, T) local u = ((T + p.off) % 220) / 220 local a = 0.55 * min(1, u * 5) * (1 - u) local y = 6 - u * 20 local x = 23 + u * 14 + 1.5 * sin(u * 6 + p.off) local w = p.w + u * 7 local iy = floor(y) local fy = y - iy for k = 0, 2 do local ww = w * (k == 1 and 1 or 0.65) local x0 = floor(x - ww / 2 + 0.5) local wi = floor(ww + 0.5) blend_rect(x0, iy + k, wi, 1, 255, 244, 252, a * (1 - fy)) blend_rect(x0, iy + k + 1, wi, 1, 255, 244, 252, a * fy) end end function render() if not BG then bake() end blit_rgb(BG, 0, 0, W, H) local T = frame * SPD[cfg.speed or 3] + START for i = 1, 4 do puff(SM[i], T) end local P = T % CYC for c = 0, W - 1 do local age = P - (c - 7 - SX0) / V if age >= 0 and age < FADE then local a = 0.6 * (1 - age / FADE) local y = lane(c) + 0.5 local iy = floor(y) local fy = y - iy blend(c, iy, 96, 156, 208, a * (1 - fy)) blend(c, iy + 1, 96, 156, 208, a * fy) end end if P < TC then local X = SX0 + V * P local q = P % 72 local a, l = 1, 1 if q < 12 then a, l = 2, 2 elseif q < 32 then a, l = 1, 1 elseif q < 44 then a, l = 2, 4 else a, l = 1, 3 end local s = cos((X + 7) * 0.105 + 0.6) local lean = s > 0.3 and 1 or (s < -0.3 and -1 or 0) local foot = floor(lane(X + 7) + 0.5) blend_rect(floor(X) + 3, foot, 9, 1, 90, 140, 200, 0.3) draw(pose(a, l, lean), PAL, X, foot - 15) end for i = 1, cfg.snow or 8 do local f = PF[i] local y = (f.y0 + T * f.v) % 70 - 3 local x = f.x + f.sw * sin(T * 0.021 + f.ph) local ix, iy = floor(x), floor(y) local fx, fy = x - ix, y - iy blend(ix, iy, 255, 255, 255, (1 - fx) * (1 - fy)) blend(ix + 1, iy, 255, 255, 255, fx * (1 - fy)) blend(ix, iy + 1, 255, 255, 255, (1 - fx) * fy) blend(ix + 1, iy + 1, 255, 255, 255, fx * fy) end end