Polygon wheel
natiny.render.poly takes a centre, a side count, a radius and a rotation in
degrees - which makes it the triangle, the hexagon and, given enough sides, the
circle.
Rotation is a parameter like any other: give each shape its own rate and a still ring becomes a mechanism. The satellites gain a side each going round.
local natiny = require("natiny")
local demo = require("common.modules.demo")
local BG = { 21 / 255, 30 / 255, 44 / 255 } -- #151E2C
local OBJECT = { 169 / 255, 179 / 255, 197 / 255 } -- #A9B3C5
local ACCENT = { 248 / 255, 249 / 255, 253 / 255 } -- #F8F9FD
local function color(c, a)
natiny.render.set_color(c[1], c[2], c[3], a or 1.0)
end
-- Two colours blended by k, so a row of shapes can carry a gradient
-- without a texture or a shader.
local function mix(a, b, k)
return { a[1] + (b[1] - a[1]) * k,
a[2] + (b[2] - a[2]) * k,
a[3] + (b[3] - a[3]) * k }
end
natiny.backend.init()
local win = natiny.window.create("Polygon wheel", 900, 600)
natiny.window.set_scale_mode(win, natiny.window.SCALE_MODE_STRETCH)
local cx, cy = 450, 300
local t = 0.0
local function frame(dt)
natiny.window.bind(win, function()
t = t + dt
natiny.render.clear(BG[1], BG[2], BG[3], 1.0)
-- ── The frame: twelve sides, turning slowly ─────────────────
color(OBJECT)
natiny.render.poly_outline(cx, cy, 12, 262, t * 6, 3)
-- ── Eight satellites, one more side each ────────────────────
for i = 0, 7 do
local a = t * 0.35 + i * (math.pi * 2 / 8)
local px = cx + math.cos(a) * 190
local py = cy + math.sin(a) * 190
local sides = 3 + i
local radius = 26 + 8 * math.sin(t * 2.0 + i)
color(mix(ACCENT, OBJECT, i / 7), 0.9)
natiny.render.poly(px, py, sides, radius, t * (40 + i * 14))
-- a looser outline turning the other way, one ring out
color(OBJECT, 0.25)
natiny.render.poly_outline(px, py, sides, radius + 6,
-t * (30 + i * 10), 3)
end
-- ── The middle: six outlines nested, alternate ones reversed ─
-- Brightest at the core and fading outward, so the stack reads as
-- one object rather than six rings that happen to share a centre.
for i = 0, 5 do
local dir = (i % 2 == 0) and 1 or -1
color(ACCENT, 0.75 - 0.09 * i)
natiny.render.poly_outline(cx, cy, 3 + i, 34 + i * 16,
dir * t * (26 + i * 9), 3)
end
color(ACCENT, 0.9)
natiny.render.poly(cx, cy, 6, 13, -t * 30)
end)
end
demo:run({
window = win,
title = "Polygon wheel",
text = "One poly call per shape: sides, radius, angle",
loop = frame,
})
natiny.backend.shutdown()