info = { type = "image", title = "Nature", category = "nature", author = "BRRRO", version = "1.0", license = "MIT", desc = "Sun, clouds, hills and birds", api = 33, } local SUN, un = {}, 0 for yy = 5, 15 do local x0, x1 = nil, nil for xx = 43, 53 do local dx, dy = xx - 48, yy - 10 if dx * dx + dy * dy <= 20 then x0 = x0 or xx x1 = xx end end if x0 then SUN[un + 1], SUN[un + 2], SUN[un + 3] = x0, yy, x1 - x0 + 1 un = un + 3 end end local CLOUD, cn = {}, 0 do local x0, dp = 0, nil for i = 0, 14 do local dy = nil if i < 14 then dy = math.floor(2 * math.sin(i * 0.55) + 0.5) end if dy ~= dp then if dp then CLOUD[cn + 1], CLOUD[cn + 2], CLOUD[cn + 3] = x0, i - x0, dp cn = cn + 3 end x0, dp = i, dy end end end local SKYL = { { 7.2, 9, 234, 240, 250 }, { 15.6, 19, 250, 252, 255 } } local RIDGE = { { 46, 5, 0.1, 0.36, 0, 150, 202, 150 }, { 53, 3, 0.2, 1.68, 1.0, 120, 182, 120 }, } local RSIN, RCOS, BG = nil, nil, nil function render() local W, H = gfx.W, gfx.H local t = frame / gfx.FPS local rect, px = gfx.rect, gfx.px if not RSIN then RSIN, RCOS = {}, {} for r = 1, 2 do local k = RIDGE[r][3] local S, C = {}, {} for x = 0, W - 1 do S[x], C[x] = math.sin(x * k), math.cos(x * k) end RSIN[r], RCOS[r] = S, C end end if not BG then for y = 0, H - 1 do local f = y / H rect(0, y, W, 1, 142 + 52 * f, 182 + 30 * f, 232 + 8 * f) end for i = 1, #SUN, 3 do rect(SUN[i], SUN[i + 1], SUN[i + 2], 1, 255, 232, 154) end BG = gfx.snapshot(0, 0, W, H) else gfx.blit_rgb(BG, 0, 0, W, H) end for l = 1, 2 do local L = SKYL[l] local span = W + 20 local off = math.floor(t * L[1]) for c = 0, 2 do local bx = (c * 26 - off) % span - 10 for i = 1, #CLOUD, 3 do rect(bx + CLOUD[i], L[2] + CLOUD[i + 2], CLOUD[i + 1], 3, L[3], L[4], L[5]) end end end for r = 1, 2 do local R = RIDGE[r] local a = t * R[4] + R[5] local ca, sa = math.cos(a), math.sin(a) local S, C = RSIN[r], RCOS[r] local base, amp = R[1], R[2] local x0, hp = 0, nil for x = 0, W do local h = nil if x < W then local v = S[x] * ca + C[x] * sa if v < 0 then v = -v end h = base - math.floor(amp * v + 0.5) end if h ~= hp then if hp then rect(x0, hp, x - x0, H - hp, R[6], R[7], R[8]) end x0, hp = x, h end end end for b = 0, 1 do local bx = math.floor(10 + b * 24 + t * 18) % (W + 10) local by = 14 + b * 4 + math.floor(math.sin(t * 6 + b) + 0.5) px(bx - 1, by - 1, 70, 76, 92) px(bx, by, 70, 76, 92) px(bx + 1, by - 1, 70, 76, 92) end end