Based on your analogy to ms paint, I'm guessing your trying to make something similar, but your own, to it. Here's another example that you can play with, which is basically a really basic (and not good) clone of ms paint. As always, code and love file attached.
Code: Select all
local mouse_positions = {}
local size = 10
local color_black = {0, 0, 0}
local color_white = {255, 255, 255}
local down = love.mouse.isDown
local get_mouse_pos = love.mouse.getPosition
function love.load()
love.graphics.setBackgroundColor(color_white)
end
function love.update(dt)
local x, y = get_mouse_pos()
if down(1) then
mouse_positions[#mouse_positions + 1] = {color_black, x, y, size}
elseif down(2) then
mouse_positions[#mouse_positions + 1] = {color_white, x, y, size}
end
end
function love.draw()
local x, y = get_mouse_pos()
for i = 1, #mouse_positions do
local obj = mouse_positions[i]
love.graphics.setColor(obj[1])
love.graphics.circle("fill", obj[2], obj[3], obj[4])
end
love.graphics.setColor(0, 0, 0)
love.graphics.circle("line", x, y, size)
end
function love.wheelmoved(x, y)
if y == 1 then
size = math.max(1, size - 1)
elseif y == -1 then
size = math.min(size + 1, 50)
end
end
What this code allows you to do is "paint" with a variable sized brushed on the screen using your left/right mouse buttons and scroll wheel. If this is more of what you were trying to go for, I recommend using what I've written more as a stepping stone to understand one way to accomplish what you're trying to do, and not just try to use it outright. The more than you continue to "paint" with this code, as in hold down the left or right mouse button - even if you're painting white - the more tables you're creating that need to be rendered to the screen. I hope I understood what you were trying to say this time lol.
- paint.love
- simple paint clone
- (499 Bytes) Downloaded 179 times