A little drawing tool
Posted: Mon Jun 19, 2017 4:26 am
This is my first post on the Love2D forum, so please excuse my lack of ability to create a neat post. I've been working on a little "code doodle" that will place a circle at the point of the mouse when the user clicks. The person can click in multiple places and the circles will connect with lines. I am new to programming and I am learning how to use tables and arrays. I was hoping to get feedback on my use of the table in this project. I was only able to achieve my goal by using the table. If there is a better way to achieve this I would like to know. Here is the code for the project:
I appreciate all feedback. Thanks!
Code: Select all
function love.load()
circle = {}
cN = -1 --Variable stands for Circle Number, it adds two to each circle. I use it to keep track of amount of circles on the screen and looping
end
function love.mousepressed(x, y, button, istouch)
if button == 1 then
printx = x
printy = y
print(x)
print(y)
cN = cN + 2
table.insert(circle, 1, printy)
table.insert(circle, 1, printx)
end
end
function love.draw()
if cN > 0 then
for i=1,cN,2 do
love.graphics.circle("fill", circle[i], circle[i + 1], 2)
end
for i=1,cN,2 do
if circle[i+2] ~= nil then
love.graphics.line(circle[i],circle[i+1],circle[i+2],circle[i+3])
end
end
end
end