How to draw rectangles, circles

Using draw_line message you can draw anything you want. For example:

local function draw_circle (position, radius, segment_count)
	local step = math.rad(360) / segment_count
	local point_a = vmath.vector3(position.x + radius, position.y, 0)
	local color = vmath.vector4(1, 0, 1, 1)
	for i = 1, segment_count do
		local angle = i * step
		local point_b = vmath.vector3(position.x + radius * math.cos(angle), position.y + radius * math.sin(angle), 0)
		msg.post("@render:", "draw_line", { start_point = point_a, end_point = point_b, color = color } )
		point_a = point_b
	end
end -- draw_circle

For debugging purposes, of course.

3 Likes