selecting a stroke

[?]
May 12, 2022, 5:01 AM
G77XIN7MLX465AXLXDUJDGEHXXCMR2Q7K25UAMKQERBJGNJPNW6AC

Dependencies

  • [2] Z2CJVAPV lighter border for figures
  • [3] EFMLTMZG bugfix: restrict strokes to the drawing they started in
  • [4] QU7NHFOV show cursor
  • [5] IZZVOCLB confirm that we have access to all of the love API
  • [6] XX7G2FFJ intermingle freehand line drawings with text
  • [7] OTIBCAUJ love2d scaffold
  • [8] TRCAEE2A clip drawings inside the border

Change contents

  • edit in main.lua at line 7
    [4.14]
    [4.14]
    mode = ''
  • edit in main.lua at line 47
    [4.805][2.48:84]()
    love.graphics.setColor(0,0,0)
  • edit in main.lua at line 48
    [4.849]
    [4.849]
    if shape.selected then
    love.graphics.setColor(1,0,0)
    else
    love.graphics.setColor(0,0,0)
    end
  • replacement in main.lua at line 82
    [4.446][4.1358:1391]()
    if love.mouse.isDown('1') then
    [4.446]
    [3.3]
    if love.mouse.isDown('1') and mode == 'draw' then
  • edit in main.lua at line 101
    [3.187]
    [3.187]
    mode = 'grab'
  • edit in main.lua at line 107
    [3.440]
    [3.440]
    for _,shape in ipairs(drawing.shapes) do
    if on_freehand(x,y, shape) then
    shape.selected = true
    return
    end
    end
  • edit in main.lua at line 116
    [3.464]
    [3.464]
    mode = 'draw'
  • edit in main.lua at line 119
    [3.469]
    [4.1769]
    function on_freehand(x,y, shape)
    local prev
    for _,p in ipairs(shape) do
    if prev then
    if on_line(x,y, {x1=prev.x,y1=prev.y, x2=p.x,y2=p.y}) then
    return true
    end
    end
    prev = p
    end
    return false
    end
    function on_line(x,y, shape)
    if shape.x1 == shape.x2 then
    local y1,y2 = shape.y1,shape.y2
    if y1 > y2 then
    y1,y2 = y2,y2
    end
    return y >= y1 and y <= y2
    end
    -- has the right slope and intercept
    local m = (shape.y2 - shape.y1) / (shape.x2 - shape.x1)
    local yp = shape.y1 + m*(x-shape.x1)
    if yp < 0.95*y or yp > 1.05*y then
    return false
    end
    -- between endpoints
    local k = (x-shape.x1) / (shape.x2-shape.x1)
    return k > -0.05 and k < 1.05
    end