Skip to content

Commit

Permalink
input stabilizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Sin-tel committed Sep 23, 2023
1 parent 987c253 commit 546a743
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ macOS and Linux work but only mouse input.
* left click: draw
* hold ctrl: erase
* hold shift: smooth
* radius determines input stabilization
### line tool
* left click: draw flat lines
* hold alt: draw slanted lines
Expand Down
32 changes: 29 additions & 3 deletions src/tool_draw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,35 @@ shift: smooth
Draw.preview = true
Draw.drawTool = true

Draw.radius = 5

Draw.x = 0
Draw.y = 0

function Draw.mousepressed()
Draw.points = {}

local pt = { mouseX, mouseY, pres }
Draw.x = mouseX
Draw.y = mouseY

local pt = { Draw.x, Draw.y, pres }
table.insert(Draw.points, pt)
Draw.lastpoint = pt
end

function Draw.mousedown()
if not (Draw.lastpoint[1] == mouseX and Draw.lastpoint[2] == mouseY) then
local dx = mouseX - Draw.x
local dy = mouseY - Draw.y

local l = math.sqrt(dx ^ 2 + dy ^ 2)
if l > Draw.radius then
Draw.x = mouseX - (Draw.radius * dx / l)
Draw.y = mouseY - (Draw.radius * dy / l)
end

if not (Draw.lastpoint[1] == Draw.x and Draw.lastpoint[2] == Draw.y) then
Draw.removePoints()
local pt = { mouseX, mouseY, pres }
local pt = { Draw.x, Draw.y, pres }
table.insert(Draw.points, pt)
table.sort(Draw.points, function(a, b)
return a[1] < b[1]
Expand Down Expand Up @@ -117,6 +134,15 @@ function Draw.simplify(i1, i2, alwaysKeep)
end

function Draw.draw()
-- love.graphics.setColor(Theme.current.cursor)

-- if not mouseDown[1] then
-- Draw.x = mouseX
-- Draw.y = mouseY
-- end

-- love.graphics.ellipse("line", Draw.x, Draw.y, 5)

love.graphics.setColor(Theme.current.draw)
for i = 1, #Draw.points - 1 do
local v1 = Draw.points[i]
Expand Down

0 comments on commit 546a743

Please sign in to comment.