switch from freehand to just straight lines

[?]
May 14, 2022, 3:42 AM
O2UFJ6G3MDBJFSABWAJWTZGP6VAKRMQ6XCMILLQRRSS43C3UF2OQC

Dependencies

  • [2] T76KKDWZ turn strokes into horizontal and vertical lines
  • [3] JVRL5TWL store device-independent coordinates inside drawings
  • [4] EFMLTMZG bugfix: restrict strokes to the drawing they started in
  • [5] OTIBCAUJ love2d scaffold
  • [6] 6LJZN727 handle chords
  • [7] IZZVOCLB confirm that we have access to all of the love API
  • [8] MNWHXPBL more lightweight; select just the stroke at the mouse
  • [9] KVHUFUFV reorg
  • [10] WAZVXUV2 simplest possible way to straighten strokes
  • [11] D2GCFTTT clean up repl functionality
  • [12] XX7G2FFJ intermingle freehand line drawings with text
  • [13] TRCAEE2A clip drawings inside the border
  • [14] Z2CJVAPV lighter border for figures
  • [15] G77XIN7M selecting a stroke
  • [16] 4NDYV4WD fix 2 bugs in line selection
  • [17] 3XD6M3CF refactor

Change contents

  • replacement in main.lua at line 60
    [4.849][3.583:625]()
    if on_freehand(mx,my, shape) then
    [4.849]
    [4.45]
    if 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 = nil
    for _,point in ipairs(shape) do
    if prev then
    love.graphics.line(pixels(prev.x)+12,pixels(prev.y)+line.y, pixels(point.x)+12,pixels(point.y)+line.y)
    end
    prev = point
    end
    [4.150]
    [4.1043]
    love.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 = nil
    for _,point in ipairs(line.pending) do
    if prev then
    love.graphics.line(pixels(prev.x)+12,pixels(prev.y)+line.y, pixels(point.x)+12,pixels(point.y)+line.y)
    end
    prev = point
    [4.1053]
    [4.1230]
    if line.pending.x1 then
    love.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
    [3.957][3.957:1068]()
    table.insert(drawing.pending, {x=coord(love.mouse.getX()-12), y=coord(love.mouse.getY()-drawing.y)})
  • edit in main.lua at line 99
    [4.142]
    [4.446]
    end
    function love.mousereleased(x,y, button)
    if lines.current then
    if lines.current.pending then
    lines.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 = nil
    end
    end
  • edit in main.lua at line 118
    [3.1168]
    [4.408]
    drawing.pending = {x1=coord(x-12), y1=coord(y-drawing.y)}
  • edit in main.lua at line 160
    [4.469][4.1769:2010](),[4.1128][4.1769:2010](),[4.451][4.1769:2010]()
    function love.mousereleased(x,y, button)
    if lines.current then
    if lines.current.pending then
    table.insert(lines.current.shapes, lines.current.pending)
    lines.current.pending = {}
    lines.current = nil
    end
    end
    end
  • edit in main.lua at line 182
    [4.1135][4.3:32](),[4.32][4.3:111](),[4.111][2.3:11]()
    elseif chord == 'C-l' then
    local drawing,i,shape = select_shape_at_mouse()
    if drawing then
    convert_line(drawing,i,shape)
    end
  • replacement in main.lua at line 197
    [4.433][3.1355:1399]()
    if on_freehand(mx,my, shape) then
    [4.433]
    [4.507]
    if on_line(mx,my, shape) then
  • edit in main.lua at line 204
    [4.607][4.493:826]()
    end
    function 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
    [2.260][2.260:445]()
    local x1,y1 = shape[1].x, shape[1].y
    local x2,y2 = shape[#shape].x, shape[#shape].y
    if math.abs(x1-x2) > math.abs(y1-y2) then
    drawing.shapes[i] = {{x=x1, y=y1}, {x=x2, y=y1}}
    [2.260]
    [2.445]
    if math.abs(shape.x1-shape.x2) > math.abs(shape.y1-shape.y2) then
    shape.y2 = shape.y1
  • replacement in main.lua at line 211
    [2.452][2.452:505]()
    drawing.shapes[i] = {{x=x1, y=y1}, {x=x1, y=y2}}
    [2.452]
    [2.505]
    shape.x2 = shape.x1