extend("math")
extend("event")
extend("kanvas")

// ─────────────────────────────────────────────────────────────
// create a 400 × 400 window and an initial triangle
// ─────────────────────────────────────────────────────────────
win = kanvas:create([width: 400, height: 400, title: "Rotating Triangle"])

orig = [
	[100, 100],
	[300, 100],
	[200, 300]
]

color  = "#FF00FF00"          // opaque green
triangle_handle = kanvas:triangle(win, orig, color)
kanvas:display(win)
kanvas:refresh(win)


angle = 0                 // cumulative rotation, in radians
step = 0.06

event:loop(() => {
	
    angle = angle + step               // advance

    p1 = math:rotate_point(orig[0][0], orig[0][1], angle)   // fresh vertices
    p2 = math:rotate_point(orig[1][0], orig[1][1], angle)
    p3 = math:rotate_point(orig[2][0], orig[2][1], angle)

    kanvas:remove(win, triangle_handle)   // erase previous triangle
    triangle_handle = kanvas:triangle(win, [p1, p2, p3], color)

    kanvas:refresh(win)                  // redraw
})
