new mode: circle arc

[?]
May 15, 2022, 5:24 AM
ZOOY3ME4BUD6RLWCKZFA62JNN4BMPOXH24HGTFWPWEKDECOXMFUAC

Dependencies

  • [2] FMQ74DP3 new mode: circle
  • [*] OTIBCAUJ love2d scaffold
  • [*] JCSLDGAH beginnings of support for multiple shapes
  • [*] NL5J7Z5H new mode: polygon
  • [*] 6LJZN727 handle chords
  • [*] H7OEU6WP experimental approach to combining keyboard and mouse while drawing

Change contents

  • edit in main.lua at line 185
    [2.427]
    [5.1962]
    elseif lines.current.pending.mode == 'arc' 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 center = lines.current.points[lines.current.pending.center]
    lines.current.pending.end_angle = angle_with_hint(center.x,center.y, mx,my, lines.current.pending.end_angle)
    table.insert(lines.current.shapes, lines.current.pending)
    end
  • edit in main.lua at line 266
    [2.798]
    [5.2834]
    elseif shape.mode == 'arc' then
    local center = drawing.points[shape.center]
    love.graphics.arc('line', 'open', pixels(center.x)+left,pixels(center.y)+top, pixels(shape.radius), shape.start_angle, shape.end_angle, 360)
    else
    print(shape.mode)
    assert(false)
  • edit in main.lua at line 316
    [2.1205]
    [5.3110]
    elseif shape.mode == 'arc' then
    local center = drawing.points[shape.center]
    local mx,my = coord(love.mouse.getX()-16), coord(love.mouse.getY()-drawing.y)
    if mx < 0 or mx >= 256 or my < 0 or my >= drawing.h then
    return
    end
    shape.end_angle = angle_with_hint(center.x,center.y, mx,my, shape.end_angle)
    local cx,cy = pixels(center.x)+left, pixels(center.y)+top
    love.graphics.arc('line', 'open', cx,cy, pixels(shape.radius), shape.start_angle, shape.end_angle, 360)
  • edit in main.lua at line 340
    [2.1352]
    [5.3287]
    elseif shape.mode == 'arc' then
    local center = drawing.points[shape.center]
    local dist = math.dist(center.x,center.y, x,y)
    if dist < shape.radius*0.95 or dist > shape.radius*1.05 then
    return false
    end
    return angle_between(center.x,center.y, x,y, shape.start_angle,shape.end_angle)
  • edit in main.lua at line 409
    [6.1934]
    [7.23]
    function angle_between(x1,y1, x2,y2, s,e)
    local angle = math.angle(x1,y1, x2,y2)
    --? print(s,e, angle-math.pi*2, angle, angle+math.pi*2)
    if s > e then
    s,e = e,s
    end
    -- I'm not sure this is right or ideal..
    angle = angle-math.pi*2
    if s <= angle and angle <= e then
    return true
    end
    angle = angle+math.pi*2
    if s <= angle and angle <= e then
    return true
    end
    angle = angle+math.pi*2
    return s <= angle and angle <= e
    end
  • edit in main.lua at line 463
    [2.1410]
    [8.141]
    elseif love.mouse.isDown('1') and chord == 'a' and current_mode == 'circle' then
    local drawing = current_drawing()
    drawing.pending.mode = 'arc'
    local mx,my = coord(love.mouse.getX()-16), coord(love.mouse.getY()-drawing.y)
    local j = insert_point(drawing.points, mx,my)
    local center = drawing.points[drawing.pending.center]
    drawing.pending.radius = math.dist(center.x,center.y, mx,my)
    drawing.pending.start_angle = math.angle(center.x,center.y, mx,my)
  • edit in main.lua at line 594
    [7.371]
    [7.460]
    end
    function angle_with_hint(x1, y1, x2, y2, hint)
    local result = math.angle(x1,y1, x2,y2)
    if hint then
    -- Smooth the discontinuity where angle goes from positive to negative.
    -- The hint is a memory of which way we drew it last time.
    while result > hint+math.pi/10 do
    result = result-math.pi*2
    end
    while result < hint-math.pi/10 do
    result = result+math.pi*2
    end
    end
    return result
    end
    -- result is from -π/2 to 3π/2, approximately adding math.atan2 from Lua 5.3
    -- (LÖVE is Lua 5.1)
    function math.angle(x1,y1, x2,y2)
    local result = math.atan((y2-y1)/(x2-x1))
    if x2 < x1 then
    result = result+math.pi
    end
    return result