Help with creating a paint program!
Posted: Sun Apr 26, 2020 9:02 pm
Hi! This is my first time posting . I'm creating a simple paint tool using Love, and the idea is that every time the mouse is clicked and moved, the coordinate of the mouse will be stored in a table (linePoints), and then be connected in the draw function. But the problem is how do you create separate lines and make them all stay on the screen :C . Right now each time I draw a new line the previous will disappear.
Thanks!!!
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