new mode: polygon

[?]
May 15, 2022, 3:50 AM
NL5J7Z5H577GPKGNS5TDRVWC55VLA2UCZE34F5WR4AJ5N265UECAC

Dependencies

  • [2] HWPK4SMP new mode: manhattan
  • [*] OTIBCAUJ love2d scaffold
  • [*] JCSLDGAH beginnings of support for multiple shapes
  • [*] S5JIPJPI .
  • [*] IFGAJAF7 add a level of indirection to vertices of shapes
  • [*] G77XIN7M selecting a stroke
  • [*] 6LJZN727 handle chords
  • [*] H7OEU6WP experimental approach to combining keyboard and mouse while drawing

Change contents

  • edit in main.lua at line 171
    [2.476]
    [5.1962]
    elseif lines.current.pending.mode == 'polygon' then
    local mx,my = coord(x-16), coord(y-lines.current.y)
    if mx >= 0 and mx < 256 and my >= 0 and my < lines.current.h then
    local j = insert_point(lines.current.points, mx,my)
    table.insert(lines.current.shapes, lines.current.pending)
    end
    table.insert(lines.current.shapes, lines.current.pending)
  • edit in main.lua at line 195
    [6.152]
    [5.2374]
    elseif current_mode == 'polygon' then
    local j = insert_point(drawing.points, coord(x-16), coord(y-drawing.y))
    drawing.pending = {mode=current_mode, vertices={j}}
  • edit in main.lua at line 234
    [7.1182]
    [5.2834]
    elseif shape.mode == 'polygon' then
    local prev = nil
    for _,point in ipairs(shape.vertices) do
    local curr = drawing.points[point]
    if prev then
    love.graphics.line(pixels(prev.x)+left,pixels(prev.y)+top, pixels(curr.x)+left,pixels(curr.y)+top)
    end
    prev = curr
    end
    -- close the loop
    local curr = drawing.points[shape.vertices[1]]
    love.graphics.line(pixels(prev.x)+left,pixels(prev.y)+top, pixels(curr.x)+left,pixels(curr.y)+top)
  • edit in main.lua at line 271
    [2.1180]
    [5.3110]
    elseif shape.mode == 'polygon' then
    -- don't close the loop on a pending polygon
    local prev = nil
    for _,point in ipairs(shape.vertices) do
    local curr = drawing.points[point]
    if prev then
    love.graphics.line(pixels(prev.x)+left,pixels(prev.y)+top, pixels(curr.x)+left,pixels(curr.y)+top)
    end
    prev = curr
    end
    love.graphics.line(pixels(prev.x)+left,pixels(prev.y)+top, love.mouse.getX(),love.mouse.getY())
  • edit in main.lua at line 292
    [2.1299]
    [5.3287]
    elseif shape.mode == 'polygon' then
    return on_polygon(x,y, drawing, shape)
  • edit in main.lua at line 343
    [8.1128]
    [9.23]
    function on_polygon(x,y, drawing, shape)
    local prev
    for _,p in ipairs(shape.vertices) do
    if prev then
    if on_line(x,y, drawing, {p1=prev, p2=p}) then
    return true
    end
    end
    prev = p
    end
    return on_line(x,y, drawing, {p1=shape.vertices[1], p2=shape.vertices[#shape.vertices]})
    end
  • edit in main.lua at line 382
    [10.141]
    [10.141]
    elseif chord == 'C-g' then
    current_mode = 'polygon'
    elseif love.mouse.isDown('1') and chord == 'p' and current_mode == 'polygon' then
    local drawing = current_drawing()
    local mx,my = coord(love.mouse.getX()-16), coord(love.mouse.getY()-drawing.y)
    local j = insert_point(drawing.points, mx,my)
    table.insert(drawing.pending.vertices, j)