info = { type = "image", title = "Ramen alley", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Isometric ramen bistro with customers at night", api = 44, } local tr = ({ sk = { ["Rain"] = "Dážď", ["Customers"] = "Zákazníci" }, cs = { ["Rain"] = "Déšť", ["Customers"] = "Zákazníci" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "rain", label = T("Rain"), type = "bool", default = false }, { key = "n", label = T("Customers"), type = "int", min = 1, max = 4, default = 3 }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local blit_rgb, snapshot, blend_mask = gfx.blit_rgb, gfx.snapshot, gfx.blend_mask local floor, sin, cos, sqrt, max = math.floor, math.sin, math.cos, math.sqrt, math.max local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local TAU = 6.2832 local SKY1, SKY2 = { 28, 24, 86 }, { 60, 56, 132 } local FAR = { 38, 34, 100 } local TOP, SIDE, ROAD = { 88, 82, 164 }, { 122, 114, 202 }, { 62, 56, 130 } local CURB, JOINT = { 154, 146, 228 }, { 66, 60, 138 } local FRONT, FRONT_L = { 42, 38, 100 }, { 98, 90, 176 } local WR, WL, WR_D = { 94, 86, 178 }, { 66, 60, 140 }, { 76, 70, 156 } local ROOF, ROOF_L, TRIM = { 134, 126, 214 }, { 166, 158, 236 }, { 168, 160, 238 } local PLINTH, DARK = { 54, 48, 118 }, { 36, 30, 90 } local WARM, WARM2, WARM3 = { 255, 208, 122 }, { 244, 164, 88 }, { 230, 178, 104 } local AWN1, AWN2 = { 190, 182, 250 }, { 112, 104, 198 } local NOREN, PALE = { 50, 42, 124 }, { 232, 228, 255 } local function T3(c) return c[1], c[2], c[3] end local function RF(u, v0, v1, z0, z1, c) local r, g, b = c[1], c[2], c[3] for v = v0, v1 - 1 do rect(68 + 2 * u - 2 * v, 9 + u + v - z1, 2, z1 - z0, r, g, b) end end local function LF(v, u0, u1, z0, z1, c) local r, g, b = c[1], c[2], c[3] for u = u0, u1 - 1 do rect(70 + 2 * u - 2 * v, 9 + u + v - z1, 2, z1 - z0, r, g, b) end end local function hs(x0, x1, y, h, c, a) if x1 <= x0 then return end a = a or 1 local r, g, b = c[1], c[2], c[3] local i0, i1 = floor(x0), floor(x1) if i0 == i1 then blend_rect(i0, y, 1, h, r, g, b, (x1 - x0) * a); return end if i1 > i0 + 1 then if a >= 1 then rect(i0 + 1, y, i1 - i0 - 1, h, r, g, b) else blend_rect(i0 + 1, y, i1 - i0 - 1, h, r, g, b, a) end end blend_rect(i0, y, 1, h, r, g, b, (i0 + 1 - x0) * a) if x1 > i1 then blend_rect(i1, y, 1, h, r, g, b, (x1 - i1) * a) end end local function glow_mask(n, k) local rows, row = {}, {} local R = (n - 1) / 2 for y = 0, n - 1 do for x = 0, n - 1 do local d = sqrt((x - R) ^ 2 + (y - R) ^ 2) row[x + 1] = d < R and floor(255 * (1 - d / R) * k) or 0 end rows[y + 1] = string.char(table.unpack(row, 1, n)) end return table.concat(rows) end local BG, PART, STAGE = nil, nil, 1 local LANT_GLOW local function st_ground() for y = 0, H - 1 do rect(0, y, W, 1, floor(SKY1[1] + (SKY2[1] - SKY1[1]) * y / 63), floor(SKY1[2] + (SKY2[2] - SKY1[2]) * y / 63), floor(SKY1[3] + (SKY2[3] - SKY1[3]) * y / 63)) end for i = 1, 16 do local h = hash32(i * 0x9E3779B1) blend_rect(umod(h, W), umod(h >> 8, 16), 1, 1, 210, 206, 255, 0.35 + umod(h >> 16, 4) * 0.12) end blend_mask(glow_mask(13, 0.5), 226, 222, 255, 46, 0, 13, 13, 13, 13, 1) rect(51, 3, 5, 5, 232, 228, 255) rect(50, 4, 7, 3, 232, 228, 255) local x = 0 local i = 0 while x < W do i = i + 1 local h = hash32(i * 0x85EBCA6B) local w, hh = 4 + umod(h, 5), 3 + umod(h >> 4, 9) local yb = 43 - x // 2 rect(x, yb - hh, w, hh + 6, T3(FAR)) if umod(h >> 9, 3) == 0 then rect(x + 1, yb - hh + 2, 1, 1, T3(WARM2)) end x = x + w end for x0 = 0, 62, 2 do local yb = 43 - x0 // 2 local ye = 79 - x0 // 2 rect(x0, yb, 2, 18, T3(TOP)) rect(x0, yb + 18, 2, 6, T3(SIDE)) rect(x0, yb + 24, 2, 1, T3(CURB)) rect(x0, yb + 25, 2, 11, T3(ROAD)) if ye < H then rect(x0, ye, 2, 5, T3(FRONT)) rect(x0, ye, 2, 1, T3(FRONT_L)) end end for v = 0, 52, 3 do for u = 9, 11 do rect(70 + 2 * u - 2 * v, 8 + u + v, 2, 1, T3(JOINT)) end end for v = 0, 50, 4 do rect(100 - 2 * v, 23 + v, 2, 1, T3(CURB)) rect(98 - 2 * v, 24 + v, 2, 1, T3(CURB)) end for v = 3, 48, 5 do rect(70 + 2 * 3 - 2 * v, 8 + 3 + v, 4, 1, T3(JOINT)) end for v = 23, 31 do blend_rect(70 + 2 * 9 - 2 * v, 8 + 9 + v, 2, 6, 255, 190, 100, 0.13) end end local function st_building() RF(9, 19, 32, 0, 2, PLINTH) RF(9, 19, 32, 2, 15, WR) for z = 5, 13, 4 do RF(9, 19, 32, z, z + 1, WR_D) end RF(9, 19, 32, 15, 16, TRIM) for v = 19, 31 do RF(9, v, v + 1, 12, 14, v % 2 == 0 and AWN1 or AWN2) end RF(9, 24, 28, 0, 12, DARK) RF(9, 25, 27, 0, 10, WARM2) RF(9, 25, 27, 8, 10, NOREN) RF(9, 29, 32, 4, 12, DARK) RF(9, 29, 32, 5, 11, WARM) RF(9, 30, 31, 5, 11, DARK) rect(24, 42, 2, 2, T3(PALE)) LF(32, 2, 9, 0, 2, PLINTH) LF(32, 2, 9, 2, 15, WL) for z = 5, 13, 4 do LF(32, 2, 9, z, z + 1, { 56, 50, 124 }) end LF(32, 2, 9, 15, 16, { 140, 132, 216 }) LF(32, 3, 5, 4, 11, DARK) LF(32, 3, 5, 5, 10, WARM3) LF(32, 6, 9, 6, 13, DARK) LF(32, 6, 9, 7, 12, { 44, 38, 108 }) LF(32, 7, 8, 8, 10, WARM) px(70 + 14 - 64, 9 + 7 + 32 - 11, T3(PALE)) rect(24, 22, 1, 27, T3(TRIM)) for y = 13, 33 do local xl = y <= 26 and 36 - (y - 13) * 2 or 10 + (y - 26) * 2 local xr = y <= 20 and 36 + (y - 13) * 2 or 50 - (y - 20) * 2 rect(xl, y, xr - xl + 1, 1, T3(ROOF)) end for u = 3, 8 do for v = 19, 31, 2 do blend_rect(68 + 2 * u - 2 * v, 9 + u + v - 16, 2, 1, 70, 62, 150, 0.25) end end for v = 19, 31 do rect(68 + 18 - 2 * v, 9 + 9 + v - 16, 2, 1, T3(ROOF_L)) end for u = 2, 8 do rect(70 + 2 * u - 64, 9 + u + 32 - 16, 2, 1, T3(ROOF_L)) end rect(31, 9, 3, 9, 58, 52, 126) rect(34, 9, 2, 9, 84, 76, 160) rect(30, 8, 7, 2, 104, 96, 184) rect(44, 25, 2, 1, T3(DARK)) rect(46, 26, 2, 1, T3(DARK)) rect(21, 45, 5, 7, 74, 66, 150) rect(21, 45, 5, 1, 120, 112, 200) rect(21, 48, 5, 1, T3(DARK)) RF(11, 14, 17, 0, 9, { 54, 48, 120 }) RF(11, 14, 16, 3, 8, { 196, 188, 252 }) rect(11, 47, 1, 15, T3(DARK)) rect(9, 44, 5, 3, T3(WARM)) blend_mask(glow_mask(17, 0.42), 255, 214, 140, 3, 36, 17, 17, 17, 17, 1) blend_rect(2, 59, 18, 3, 255, 190, 100, 0.1) BG = snapshot(0, 0, W, H) end local STAGES = { st_ground, st_building } function on_settings() BG, STAGE = nil, 1 end local SHIRT = { { 212, 206, 252 }, { 122, 114, 214 }, { 242, 172, 98 }, { 170, 162, 240 } } local HAIR = { { 28, 24, 66 }, { 232, 222, 164 }, { 60, 44, 40 } } local UMB = { { 82, 72, 176 }, { 238, 136, 100 }, { 150, 132, 232 } } local PANTS, SKIN = { 36, 32, 92 }, { 236, 196, 160 } local function walker(cx, fy, step, a, h, rain) local sh, hr = SHIRT[1 + umod(h, 4)], HAIR[1 + umod(h >> 3, 3)] hs(cx - 2, cx + 2, fy - 1, 1, JOINT, 0.5 * a) if step then hs(cx - 2, cx - 1, fy - 3, 2, PANTS, a); hs(cx + 1, cx + 2, fy - 3, 2, PANTS, a) else hs(cx - 1.5, cx - 0.5, fy - 3, 2, PANTS, a); hs(cx + 0.5, cx + 1.5, fy - 3, 2, PANTS, a) end hs(cx - 2, cx + 2, fy - 7, 4, sh, a) hs(cx - 1.5, cx + 1.5, fy - 9, 2, SKIN, a) hs(cx - 1.5, cx + 1.5, fy - 10, 1, hr, a) if rain then local u = UMB[1 + umod(h >> 6, 3)] hs(cx - 2.5, cx + 2.5, fy - 13, 1, u, a) hs(cx - 3.5, cx + 3.5, fy - 12, 1, u, a) hs(cx - 0.5, cx + 0.5, fy - 11, 1, DARK, a) end end local CY, WALK, IN, DOORT = 22, 2.95, 6, 0.6 local LANE, VD = 10.5, 26.25 local flap = 0 local function customer(i, t) local c = (t + (i - 1) * CY / 4) / CY local cyc = floor(c) local ph = (c - cyc) * CY local arrive = ph < WALK + DOORT local u, v, a local h = hash32(cyc * 0x9E3779B1 + i * 0x85EBCA6B) if arrive then if ph < WALK then u, v, a = LANE, 11.5 + 5 * ph, 1 else local k = (ph - WALK) / DOORT u, v, a = LANE - (LANE - 9.2) * k, VD, 1 - k flap = 1 end else ph = ph - (WALK + DOORT + IN) if ph < 0 then return end h = hash32(h + 0x7F4A7C15) if ph < DOORT then local k = ph / DOORT u, v, a = 9.2 + (LANE - 9.2) * k, VD, k flap = 1 elseif ph < DOORT + 4.25 then u, v, a = LANE, VD + 5 * (ph - DOORT), 1 else return end end if a <= 0.04 then return end local x, y = 70 + 2 * u - 2 * v, 8 + u + v walker(x, floor(y + 0.5) - 1, floor(t * 4) % 2 == 0, a, h, cfg.rain) end local SP = {} for i = 1, 6 do SP[i] = { ph = i / 6, dx = (hash32(i * 0x27D4EB2F) & 7) / 7 } end local RAIN = {} for i = 1, 26 do local h = hash32(i * 0xC2B2AE35) RAIN[i] = { x = umod(h, W + 24) - 12, y = umod(h >> 8, 80), v = 70 + umod(h >> 16, 20) } end local DROP = { 190, 186, 255 } function render() if not BG then if STAGE > 1 then blit_rgb(PART, 0, 0, W, H) end STAGES[STAGE]() STAGE = STAGE + 1 if STAGE <= #STAGES then PART = snapshot(0, 0, W, H) end gfx.ready(false) return end local t = frame / FPS blit_rgb(BG, 0, 0, W, H) local th = (0.2 + 0.12 * sin(t * TAU / 11)) * sin(t * TAU / 2.6) local lx, ly = 47 + 5 * sin(th), 26 + 5 * cos(th) if not LANT_GLOW then LANT_GLOW = glow_mask(15, 0.34) end blend_mask(LANT_GLOW, 255, 176, 90, floor(lx + 0.5) - 7, floor(ly + 0.5) - 7, 15, 15, 15, 15, 0.8 + 0.2 * sin(t * 5)) local iy = floor(ly + 0.5) hs(lx - 0.5, lx + 0.5, iy - 4, 1, DARK) hs((47 + lx) / 2 - 0.5, (47 + lx) / 2 + 0.5, iy - 5, 1, DARK) hs(lx - 1, lx + 1, iy - 3, 1, DARK) hs(lx - 1, lx + 1, iy - 2, 1, WARM2) hs(lx - 2, lx + 2, iy - 1, 1, WARM) hs(lx - 2.5, lx + 2.5, iy, 2, WARM) hs(lx - 2, lx + 2, iy + 2, 1, WARM2) hs(lx - 1, lx + 1, iy + 3, 1, DARK) hs(lx - 0.5, lx + 0.5, iy + 4, 1, WARM2) hs(lx - 2.5, lx + 2.5, iy + 1, 1, { 150, 70, 70 }, 0.7) flap = 0 for i = 1, cfg.n or 3 do customer(i, t) end local amp = flap > 0 and 1.6 or 0.8 for k = 0, 1 do local v = 26 - k local sx = floor(amp * sin(t * 1.5 + k * 1.3) + 0.5) rect(86 - 2 * v + sx, 10 + v, 2, 2, T3(NOREN)) if k == 0 then px(86 - 2 * v + sx, 10 + v, T3(PALE)) end end for i = 1, 6 do local k = (t / 3.8 + SP[i].ph) % 1 local cx = 33 + 8 * k + 1.2 * sin(k * 9 + i) local r = 1 + 2.6 * k local a = 0.5 * (1 - k) local y = 7 - floor(11 * k) hs(cx - r * 0.6, cx + r * 0.6, y - 1, 1, PALE, a) hs(cx - r, cx + r, y, 1, PALE, a) hs(cx - r * 0.6, cx + r * 0.6, y + 1, 1, PALE, a) end for i = 1, 2 do local k = (t / 2.4 + i * 0.5) % 1 hs(25 + i * 1.4 + 0.5 * sin(k * 8 + i), 26 + i * 1.4 + 0.5 * sin(k * 8 + i), 41 - floor(4 * k), 1, PALE, 0.55 * (1 - k)) end if cfg.rain then for i = 1, 26 do local d = RAIN[i] local y = (d.y + t * d.v) % 80 - 8 blend_rect(d.x + floor(y * 0.12), floor(y), 1, 3, DROP[1], DROP[2], DROP[3], 0.5) end end end