Skip to content

Commit

Permalink
Create Point.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
markalanboyd committed Dec 23, 2023
1 parent 2421b93 commit 7823a78
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/draw/Point.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Point = {}
Point.__index = Point

function Point.new(vec2, color, size)
local self = setmetatable({}, Point)
self.vec2 = vec2 or { x = 0, y = 0 }
self.color = color or { 1, 1, 1, 1 }
self.size = size or 2
return self
end

function Point.draw_all(...)
local args = { ... }
local points

if type(args[1]) == "table" then
if getmetatable(args[1]) == Point then
points = args
else
points = args[1]
end
else
points = args
end

for _, point in ipairs(points) do
if getmetatable(point) == Point then
point:draw()
else
error("Invalid argument to Point.draw_all:" ..
"Expected a Point instance or a table of Point instances")
end
end
end

function Point:draw()
fill_circle({ self.vec2.x, self.vec2.y },
self.size,
color_paint(self.color)
)
end

0 comments on commit 7823a78

Please sign in to comment.