info = { type = "image", title = "Cloud nap", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A girl naps on a cloud and dreams on", api = 33, } local tr = ({ sk = { ["Sky"] = "Obloha", ["dusk"] = "súmrak", ["night"] = "noc", ["dawn"] = "svitanie", ["Show Z Z Z"] = "Ukázať Z Z Z", ["Speed"] = "Rýchlosť" }, cs = { ["Sky"] = "Obloha", ["dusk"] = "soumrak", ["night"] = "noc", ["dawn"] = "svítání", ["Show Z Z Z"] = "Zobrazit Z Z Z", ["Speed"] = "Rychlost" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "sky", label = T("Sky"), type = "int", default = 0, opts = { T("dusk"), T("night"), T("dawn") } }, { key = "zzz", label = T("Show Z Z Z"), type = "bool", default = true }, { key = "speed", label = T("Speed"), type = "int", min = 1, max = 5, default = 3 }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, cos = math.floor, math.sin, math.cos local hash32 = math.hash32 local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local TAU = 6.28318 local SKYS = { { { 38, 28, 96 }, { 96, 56, 138 }, { 160, 128, 208 }, { 126, 94, 178 }, { 236, 222, 255 }, { 190, 170, 236 }, { 238, 104, 150 }, { 178, 62, 118 }, { 255, 156, 194 } }, { { 16, 20, 62 }, { 40, 46, 112 }, { 70, 78, 150 }, { 50, 56, 120 }, { 150, 160, 220 }, { 110, 120, 190 }, { 56, 168, 176 }, { 30, 112, 130 }, { 120, 220, 220 } }, { { 92, 84, 170 }, { 255, 168, 138 }, { 255, 214, 196 }, { 236, 172, 168 }, { 255, 240, 232 }, { 244, 196, 196 }, { 126, 96, 206 }, { 86, 62, 160 }, { 176, 150, 240 } }, } local K = SKYS[1] local STAR, STAR_DIM = { 255, 252, 226 }, { 150, 150, 200 } local PILLOW, PILLOW_D = { 250, 242, 255 }, { 216, 200, 242 } local SKIN, SKIN_D = { 255, 208, 172 }, { 232, 176, 146 } local HAIR, HAIR_L = { 84, 46, 48 }, { 128, 76, 68 } local LASH = { 90, 46, 56 } local MOON = { 255, 246, 200 } local HX, HEAD_Y = 32, 19 local function c3(c) return c[1], c[2], c[3] end local function srect(xf, y, w, h, c) local ix = floor(xf) local f = xf - ix rect(ix + 1, y, w - 1, h, c[1], c[2], c[3]) if f < 0.97 then blend_rect(ix, y, 1, h, c[1], c[2], c[3], 1 - f) end if f > 0.03 then blend_rect(ix + w, y, 1, h, c[1], c[2], c[3], f) end end local function cloud(xf, y, L, k, lite, shade) local h = 2 * k srect(xf + L * 0.28, y, floor(L * 0.42), h, lite) srect(xf + L * 0.08, y + h, floor(L * 0.84), h, lite) srect(xf, y + 2 * h, L, h, lite) srect(xf, y + 3 * h - 1, L, 1, shade) end local SX, SY, SP = {}, {}, {} do local k, i = 0, 0 while k < 14 and i < 200 do i = i + 1 local h = hash32(i * 0x9E3779B1) local x, y = (h & 0x7FFF) % W, ((h >> 8) & 0x7FFF) % 26 if not (x < 20 and y < 14) and not (x > 20 and x < 46 and y > 16) then k = k + 1 SX[k], SY[k], SP[k] = x, y, ((h >> 16) & 0x7FFF) % 628 / 100.0 end end end local BG = nil local function build_bg() local a, b = K[1], K[2] local G0, G1 = 12, 32 rect(0, 0, W, G0, c3(a)) for y = G0, G1 - 1 do local t = (y - G0 + 1) / (G1 - G0 + 1) rect(0, y, W, 1, 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 rect(0, G1, W, H - G1, c3(b)) for y = 4, 13 do for x = 6, 15 do local dx, dy = x - 10.5, y - 8.5 local ex, ey = x - 12.5, y - 7.5 if dx * dx + dy * dy <= 20 and ex * ex + ey * ey > 14 then px(x, y, c3(MOON)) end end end rect(20, 28, 24, 1, c3(PILLOW)) rect(15, 29, 34, 1, c3(PILLOW)) rect(12, 30, 40, 6, c3(PILLOW)) rect(12, 36, 40, 3, c3(PILLOW_D)) rect(15, 39, 34, 1, c3(PILLOW_D)) rect(0, 58, W, 6, c3(K[6])) BG = gfx.snapshot(0, 0, W, H) end function on_settings() K = SKYS[(cfg.sky or 0) + 1] or SKYS[1] BG = nil end local function draw_girl(bz, exhale) local hy = HEAD_Y - (bz > 0.6 and 1 or 0) rect(HX - 10, hy + 3, 20, 17, c3(HAIR)) rect(HX - 8, hy, 16, 3, c3(HAIR)) rect(HX - 9, hy + 1, 18, 2, c3(HAIR)) rect(HX - 7, hy + 5, 14, 9, c3(SKIN)) rect(HX - 6, hy + 14, 12, 1, c3(SKIN)) rect(HX - 5, hy + 15, 10, 1, c3(SKIN)) rect(HX - 3, hy + 16, 6, 3, c3(SKIN_D)) rect(HX - 7, hy + 3, 14, 3, c3(HAIR)) for x = HX - 7, HX + 5, 2 do px(x, hy + 6, c3(HAIR)) end px(HX - 5, hy + 4, c3(HAIR_L)); px(HX - 4, hy + 4, c3(HAIR_L)); px(HX + 2, hy + 3, c3(HAIR_L)) px(HX - 6, hy + 11, c3(LASH)); px(HX - 5, hy + 12, c3(LASH)); px(HX - 4, hy + 12, c3(LASH)); px(HX - 3, hy + 11, c3(LASH)) px(HX + 2, hy + 11, c3(LASH)); px(HX + 3, hy + 12, c3(LASH)); px(HX + 4, hy + 12, c3(LASH)); px(HX + 5, hy + 11, c3(LASH)) blend_rect(HX - 7, hy + 13, 2, 1, 255, 120, 140, 0.55) blend_rect(HX + 5, hy + 13, 2, 1, 255, 120, 140, 0.55) if exhale then rect(HX - 1, hy + 14, 2, 2, 168, 70, 84) else rect(HX - 1, hy + 15, 2, 1, 190, 90, 100) end end local function draw_blanket(yf) local iy = floor(yf) local fr = yf - iy local L, D, S = K[7], K[8], K[9] blend_rect(HX - 9, iy, 18, 1, L[1], L[2], L[3], 1 - fr) rect(HX - 9, iy + 1, 18, 1, c3(L)) rect(HX - 15, iy + 2, 30, 1, c3(L)) rect(HX - 20, iy + 3, 40, 3, c3(L)) rect(HX - 22, iy + 6, 44, 14, c3(L)) rect(HX - 22, iy + 8, 44, 1, c3(S)) rect(HX - 22, iy + 15, 44, 4, c3(D)) for k = 0, 3 do px(HX - 16 + k * 9, iy + 12 + (k % 2) * 3, 255, 236, 150) end end local ZF = { { font = "3x5", alpha = 1 }, { font = "4x6", alpha = 1 }, { font = "5x7", alpha = 1 } } local function draw_z(f, spd) local per = 150 for k = 0, 2 do local tau = (f * spd + k * 50) % per local u = tau / per local o = u < 0.35 and ZF[1] or (u < 0.7 and ZF[2] or ZF[3]) o.alpha = u < 0.15 and u / 0.15 or (u > 0.72 and (1 - u) / 0.28 or 1) local x = floor(43 + u * 9 + 2.5 * sin(u * TAU * 1.5 + k)) local y = floor(27 - u * 24) if o.alpha > 0.05 then gfx.text(x, y, "Z", 236, 230, 255, o) end end end local BACK = { { 3, 20, 0.12, 30 }, { 16, 26, -0.10, 40 }, { 27, 22, 0.20, 5 } } local FRONT = { { 52, 44, 0.12, 0 }, { 52, 40, -0.09, 70 } } function render() if not BG then build_bg() end local f = frame * STEP_HZ // FPS local spd = (cfg.speed or 3) / 3.0 gfx.blit_rgb(BG, 0, 0, W, H) for k = 1, #SX do local v = sin(f * 0.06 * spd + SP[k] * 3) if v > 0.55 then px(SX[k], SY[k], c3(STAR)) px(SX[k] - 1, SY[k], c3(STAR_DIM)); px(SX[k] + 1, SY[k], c3(STAR_DIM)) px(SX[k], SY[k] - 1, c3(STAR_DIM)); px(SX[k], SY[k] + 1, c3(STAR_DIM)) elseif v > -0.3 then px(SX[k], SY[k], c3(STAR_DIM)) end end for k = 1, #BACK do local c = BACK[k] local L = c[2] cloud((c[4] + f * c[3] * spd) % (W + L) - L, c[1], L, 1, K[3], K[4]) end local ph = f * spd * TAU / (STEP_HZ * 3.6) local bz = 0.5 + 0.5 * sin(ph) draw_girl(bz, cos(ph) < -0.15) draw_blanket(38 - 1.2 * bz) if cfg.zzz ~= false then draw_z(f, spd) end for k = 1, #FRONT do local c = FRONT[k] local L = c[2] cloud((c[4] + f * c[3] * spd) % (W + L) - L, c[1], L, 1, K[5], K[6]) end end