Code: Select all
function love.load()
lineSegment = {} --create lineSegment table
end
function love.update(dt)
end
function love.draw()
if love.mouse.isDown("1") == true then --if mouse is pressed
for i, p in ipairs (lineSegment) do -- for each linePoints in lineSegments
if tablelength(linePoints) >= 3 then -- call tablelength function, if length of table is > 3, draw linePoints
love.graphics.line(linePoints)
end
end
end
end
function love.mousepressed( x, y, button, istouch, presses )
linePoints = {} -- on mouse pressed create new line point table
table.insert(lineSegment, linePoints) --insert them to lineSegment table so it can be drawn
if love.mouse.isDown("1") then
function love.mousemoved( x, y, dx, dy, istouch )--if mouse is hold down and moving
table.insert(linePoints, x) -- insert x, y, point into linepoints table
table.insert(linePoints, y)
end
end
end
function love.mousereleased( x, y, button, istouch, presses )
--linePoints = {}
table.insert(lineSegment, linePoints) --when mouse is released, insert linePoint into linesegment
print(tablelength(linePoints).."a")
print(tablelength(lineSegment).."bbbb")
end
function tablelength(t) -- a function to count the length of table
local count = 0
for _ in pairs(t) do count = count + 1 end
return count
end