Primitives
A window, and one frame's worth of drawing. Every call goes to the target
bound by natiny.window.bind; natiny.render.set_color holds until the next one
changes it.
Filled shapes on the top row, the same ones outlined below.
local natiny = require("natiny")
local demo = require("common.modules.demo")
natiny.backend.init()
local win = natiny.window.create("Primitives", 900, 600)
natiny.window.set_scale_mode(win, natiny.window.SCALE_MODE_STRETCH)
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)
natiny.render.set_color(c[1], c[2], c[3], 1.0)
end
local function frame(dt)
natiny.window.bind(win, function()
natiny.render.clear(BG[1], BG[2], BG[3], 1.0)
-- filled, on the top row
color(ACCENT)
natiny.render.rectangle(50, 80, 180, 120)
color(OBJECT)
natiny.render.circle(350, 140, 65)
color(ACCENT)
natiny.render.triangle(500, 205, 590, 75, 680, 205)
color(OBJECT)
natiny.render.poly(800, 140, 6, 60, 0)
-- the same shapes, outlined, on the bottom row
color(ACCENT)
natiny.render.rectangle_outline(50, 340, 180, 120, 3)
color(OBJECT)
natiny.render.circle_outline(350, 400, 65, 3)
color(ACCENT)
natiny.render.triangle_outline(500, 465, 590, 335, 680, 465, 3)
color(OBJECT)
natiny.render.poly_outline(800, 400, 6, 60, 0, 3)
-- a line is its own primitive: two points and a width
color(OBJECT)
natiny.render.line(50, 270, 850, 270, 2)
end)
end
demo:run({
window = win,
title = "Primitives",
text = "Filled on the top row, outlined on the bottom",
loop = frame,
})
natiny.backend.shutdown()