We start out drawing a circle, but instead of releasing the mouse we hit 'a'.
ZOOY3ME4BUD6RLWCKZFA62JNN4BMPOXH24HGTFWPWEKDECOXMFUAC
FMQ74DP324YKGBSTNMHBJMT6FYP5NI26MM43VUPGKODI5DVDCUXQC
JCSLDGAH2F6AIY4Z6XM6K4LOMW7EFY3E4NF5YXLMHLTYTX3A4Z3QC
OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC
NL5J7Z5H577GPKGNS5TDRVWC55VLA2UCZE34F5WR4AJ5N265UECAC
6LJZN727CRPYR34LV75CQF55YZI3E7MGESYZSFSYAE73SNEZE3FAC
H7OEU6WPOKOSKV5RNAM5W62V5SYOY7VEA5VOK6JD5UEBUBIMOKUQC
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
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)
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
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)
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