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

win = kanvas:create([width: 400, height: 400, title: "Rotating Triangle"])

// All coordinates as float arrays for accuracy and performance:
orig = [
  [100.0, 100.0],
  [300.0, 100.0],
  [200.0, 300.0]
]

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

angle = 0.0
step = 0.1

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

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

		new = [p1, p2, p3]

		slog(new)
    kanvas:remove(win, triangle_handle)
    triangle_handl = kanvas:triangle(win, new, color)

    kanvas:refresh(win)
})

