switch from freehand to just straight lines
[?]
May 14, 2022, 3:42 AM
O2UFJ6G3MDBJFSABWAJWTZGP6VAKRMQ6XCMILLQRRSS43C3UF2OQCDependencies
- [2]
T76KKDWZturn strokes into horizontal and vertical lines - [3]
JVRL5TWLstore device-independent coordinates inside drawings - [4]
EFMLTMZGbugfix: restrict strokes to the drawing they started in - [5]
OTIBCAUJlove2d scaffold - [6]
6LJZN727handle chords - [7]
IZZVOCLBconfirm that we have access to all of the love API - [8]
MNWHXPBLmore lightweight; select just the stroke at the mouse - [9]
KVHUFUFVreorg - [10]
WAZVXUV2simplest possible way to straighten strokes - [11]
D2GCFTTTclean up repl functionality - [12]
XX7G2FFJintermingle freehand line drawings with text - [13]
TRCAEE2Aclip drawings inside the border - [14]
Z2CJVAPVlighter border for figures - [15]
G77XIN7Mselecting a stroke - [16]
4NDYV4WDfix 2 bugs in line selection - [17]
3XD6M3CFrefactor
Change contents
- replacement in main.lua at line 60
if on_freehand(mx,my, shape) thenif on_line(mx,my, shape) then - replacement in main.lua at line 65[4.150]→[4.849:931](∅→∅),[4.849]→[4.849:931](∅→∅),[4.931]→[3.626:741](∅→∅),[3.741]→[4.994:1043](∅→∅),[4.994]→[4.994:1043](∅→∅)
prev = nilfor _,point in ipairs(shape) doif prev thenlove.graphics.line(pixels(prev.x)+12,pixels(prev.y)+line.y, pixels(point.x)+12,pixels(point.y)+line.y)endprev = pointendlove.graphics.line(pixels(shape.x1)+12,pixels(shape.y1)+line.y, pixels(shape.x2)+12,pixels(shape.y2)+line.y) - replacement in main.lua at line 67[4.1053]→[4.1053:1136](∅→∅),[4.1136]→[3.742:855](∅→∅),[3.855]→[4.1197:1230](∅→∅),[4.1197]→[4.1197:1230](∅→∅)
prev = nilfor _,point in ipairs(line.pending) doif prev thenlove.graphics.line(pixels(prev.x)+12,pixels(prev.y)+line.y, pixels(point.x)+12,pixels(point.y)+line.y)endprev = pointif line.pending.x1 thenlove.graphics.line(pixels(line.pending.x1)+12,pixels(line.pending.y1)+line.y, love.mouse.getX(),love.mouse.getY()) - edit in main.lua at line 90
table.insert(drawing.pending, {x=coord(love.mouse.getX()-12), y=coord(love.mouse.getY()-drawing.y)}) - edit in main.lua at line 99
endfunction love.mousereleased(x,y, button)if lines.current thenif lines.current.pending thenlines.current.pending.x2 = coord(x-12)lines.current.pending.y2 = coord(y-lines.current.y)table.insert(lines.current.shapes, lines.current.pending)lines.current.pending = {}lines.current = nilendend - edit in main.lua at line 118
drawing.pending = {x1=coord(x-12), y1=coord(y-drawing.y)} - edit in main.lua at line 160
function love.mousereleased(x,y, button)if lines.current thenif lines.current.pending thentable.insert(lines.current.shapes, lines.current.pending)lines.current.pending = {}lines.current = nilendendend - edit in main.lua at line 182
elseif chord == 'C-l' thenlocal drawing,i,shape = select_shape_at_mouse()if drawing thenconvert_line(drawing,i,shape)end - replacement in main.lua at line 197
if on_freehand(mx,my, shape) thenif on_line(mx,my, shape) then - edit in main.lua at line 204
endfunction convert_line(drawing, i, shape)-- Perhaps we should do a more sophisticated "simple linear regression"-- here:-- https://en.wikipedia.org/wiki/Linear_regression#Simple_and_multiple_linear_regression-- But this works well enough for close-to-linear strokes.drawing.shapes[i] = {shape[1], shape[#shape]} - replacement in main.lua at line 208
local x1,y1 = shape[1].x, shape[1].ylocal x2,y2 = shape[#shape].x, shape[#shape].yif math.abs(x1-x2) > math.abs(y1-y2) thendrawing.shapes[i] = {{x=x1, y=y1}, {x=x2, y=y1}}if math.abs(shape.x1-shape.x2) > math.abs(shape.y1-shape.y2) thenshape.y2 = shape.y1 - replacement in main.lua at line 211
drawing.shapes[i] = {{x=x1, y=y1}, {x=x1, y=y2}}shape.x2 = shape.x1