info = { type = "image", title = "Cat in the window", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "A cat asleep on the windowsill", api = 33, } local px, rect, blend = gfx.px, gfx.rect, gfx.blend local floor, sin, fmod = math.floor, math.sin, math.fmod local hash32, schar, concat, unpack = math.hash32, string.char, table.concat, table.unpack local W, H = gfx.W, gfx.H local WALL, WALL_D = { 58, 38, 30 }, { 40, 25, 20 } local FRAME, FRAME_L, FRAME_D = { 104, 62, 34 }, { 138, 88, 50 }, { 68, 40, 22 } local SILL, SILL_L = { 126, 80, 44 }, { 158, 108, 62 } local SKY = { 16, 18, 48 } local MOON, MOON_D = { 246, 240, 200 }, { 214, 206, 160 } local POT, POT_D, LEAF, LEAF_D = { 168, 88, 52 }, { 122, 60, 34 }, { 60, 150, 70 }, { 36, 106, 50 } local PANE = { { 9, 7, 29, 23 }, { 35, 7, 55, 23 }, { 9, 27, 29, 44 }, { 35, 27, 55, 44 }, } local SILL_Y = 47 local function in_pane(x, y) for i = 1, 4 do local p = PANE[i] if x >= p[1] and x <= p[3] and y >= p[2] and y <= p[4] then return true end end return false end local C_W, C_H = 24, 13 local CAT = { "........................", "................k...k...", "...............kok.kok..", ".......kkkkkkkkdokkkodk.", "....kkkoodoodooooooook..", "...koodoodoodoooooooook.", "..kooodoodoodooooooooook", ".koooodoodoodooookokoook", ".kdooodoodoodooooopooook", ".kdoooooooooooooooooook.", ".kdooooooooddooooooook..", "..kkoooddddoowwwwookk...", "...kkooooooooookkk......", } local C_IX = { k = 1, o = 2, d = 3, w = 4, p = 5 } local C_PAL = { 0, 0, 0, 20, 12, 8, 230, 140, 60, 180, 98, 38, 245, 225, 200, 255, 170, 180 } local C_SPR do local rows, row = {}, {} for j = 1, C_H do for i = 1, C_W do row[i] = C_IX[CAT[j]:sub(i, i)] or 0 end rows[j] = schar(unpack(row, 1, C_W)) end C_SPR = concat(rows) end local N_STAR = 22 local function draw_sky(f) for i = 1, 4 do local p = PANE[i] rect(p[1], p[2], p[3] - p[1] + 1, p[4] - p[2] + 1, SKY[1], SKY[2], SKY[3]) end for i = 1, N_STAR do local h = hash32(i * 0x9E3779B1) local x, y = 8 + h % 48, 6 + (h >> 8) % 38 if in_pane(x, y) then local k = 0.5 + 0.5 * sin(fmod(f * (0.6 + (h >> 4) % 26 * 0.03) + (h >> 16) % 628 / 100.0, 6.28318)) blend(x, y, 230, 236, 255, 0.25 + 0.75 * k) end end local mx = 6 + fmod(f * 0.126, 1.0) * 56 local my = 14 + 3 * sin(fmod(f * 0.12, 6.28318)) for dy = -4, 4 do for dx = -4, 4 do if dx * dx + dy * dy <= 18 then local x, y = floor(mx + dx), floor(my + dy) if in_pane(x, y) then local c = (dx > 1 and dy < 1 and dx * dx + dy * dy > 8) and MOON_D or MOON px(x, y, c[1], c[2], c[3]) end end end end end local function draw_room() rect(0, 0, W, 4, WALL[1], WALL[2], WALL[3]) rect(0, 0, 6, SILL_Y, WALL[1], WALL[2], WALL[3]) rect(58, 0, 6, SILL_Y, WALL[1], WALL[2], WALL[3]) rect(0, SILL_Y + 5, W, H - SILL_Y - 5, WALL_D[1], WALL_D[2], WALL_D[3]) rect(6, 4, 52, 3, FRAME[1], FRAME[2], FRAME[3]) rect(6, 4, 52, 1, FRAME_L[1], FRAME_L[2], FRAME_L[3]) rect(6, 45, 52, 2, FRAME_D[1], FRAME_D[2], FRAME_D[3]) rect(6, 4, 3, 43, FRAME[1], FRAME[2], FRAME[3]) rect(55, 4, 3, 43, FRAME[1], FRAME[2], FRAME[3]) rect(30, 4, 5, 43, FRAME[1], FRAME[2], FRAME[3]) rect(30, 4, 1, 43, FRAME_L[1], FRAME_L[2], FRAME_L[3]) rect(6, 24, 52, 3, FRAME[1], FRAME[2], FRAME[3]) rect(6, 24, 52, 1, FRAME_L[1], FRAME_L[2], FRAME_L[3]) rect(0, SILL_Y, W, 1, SILL_L[1], SILL_L[2], SILL_L[3]) rect(0, SILL_Y + 1, W, 3, SILL[1], SILL[2], SILL[3]) rect(0, SILL_Y + 4, W, 1, FRAME_D[1], FRAME_D[2], FRAME_D[3]) rect(3, 40, 9, 7, POT[1], POT[2], POT[3]) rect(3, 40, 9, 1, POT_D[1], POT_D[2], POT_D[3]) rect(4, 44, 7, 3, POT_D[1], POT_D[2], POT_D[3]) for i = 0, 4 do local dir = i < 2 and -1 or 1 local x0 = 7 + (i - 2) * 2 local len = 7 + (i % 2) * 3 for j = 0, len - 1 do local x = x0 + floor(dir * j * j / 18) local y = 39 - j local c = j > len - 3 and LEAF or LEAF_D rect(x, y, 2, 1, c[1], c[2], c[3]) end end end local TAIL, TAIL_K = { 230, 140, 60 }, { 20, 12, 8 } local function draw_tail(f, x0, y0) local ph = fmod(f * 1.05, 6.28318) for i = 0, 8 do local t = i / 8.0 local x = x0 - i local y = y0 + floor(3.0 * t * sin(ph + t * 1.6) + 0.5) rect(x, y, 1, 2, TAIL[1], TAIL[2], TAIL[3]) px(x, y - 1, TAIL_K[1], TAIL_K[2], TAIL_K[3]) px(x, y + 2, TAIL_K[1], TAIL_K[2], TAIL_K[3]) end end function render() local t = frame / gfx.FPS draw_sky(t) draw_room() local b = floor(0.5 + 0.5 * sin(fmod(t * 1.95, 6.28318))) local cy = SILL_Y - C_H - b draw_tail(t, 25, cy + 10) gfx.blit_indexed(C_SPR, C_PAL, 24, cy, C_W, C_H, C_W, C_H, true) local e = frame % (gfx.FPS * 12) if e < gfx.FPS // 2 then rect(24 + 15, cy + 1, 2, 1, 230, 140, 60) px(24 + 15, cy, 20, 12, 8) end end