JCSLDGAH2F6AIY4Z6XM6K4LOMW7EFY3E4NF5YXLMHLTYTX3A4Z3QC
KCIM5UTVV4KIL7SNRZFOW6FUQHGWAPOGQO4QTVNIWWBWMVG6GYNQC
HRWN5V6J6VMXS7WNSRGI7WMUSZ2OI52JJ4IK352VVSDZI4EF5HHQC
6LJZN727CRPYR34LV75CQF55YZI3E7MGESYZSFSYAE73SNEZE3FAC
OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC
2C7CTIQYDDYVQJNKX2OSHZ6VMAMPOGNUVTSFAUV7HQCPMZR2YRUAC
JVRL5TWLBTWMTHJDZSDN5XQDMEIIPVAZBKUP75HMO7JHURAYWG5QC
XX7G2FFJ4QCGQGD4REAW5QFHVYAKCFUPGZCK7L6DFGS5ISVBYBQQC
G77XIN7MLX465AXLXDUJDGEHXXCMR2Q7K25UAMKQERBJGNJPNW6AC
O2UFJ6G3MDBJFSABWAJWTZGP6VAKRMQ6XCMILLQRRSS43C3UF2OQC
EFMLTMZG5TUEGLSYLVKOKDSTGVSVWSKOMS7CJWOUGK5LADSH4YTQC
T76KKDWZLQSWMXT2ZE2PPNKBKB4W5M4BW5E6ICHKEBDAUBN6FMZAC
3XD6M3CFKZJR365MHXUWJ4HGSDTPYO6WYZ4RGW7ECBBITKVQX24QC
-- lines is an array of lines
-- a line is either:
-- a string containing text
-- or a drawing
-- a drawing is a table with:
-- a (y) coord in pixels,
-- a (h)eight,
-- an array of points, and
-- an array of shapes
-- a shape is a table containing:
-- a mode
-- an array points for mode 'freehand' (raw x,y coords; freehand drawings don't pollute the points array of a drawing)
-- an array vertices for mode 'polygon', 'rectangle', 'square'
-- p1, p2 for mode 'line'
-- p1, p2, arrow-mode for mode 'arrow-line'
-- cx,cy, r for mode 'circle'
-- pc, r for mode 'circle'
-- pc, r, s, e for mode 'arc'
-- Unless otherwise specified, coord fields are normalized; a drawing is always 256 units wide
-- The field names are carefully chosen so that switching modes in midstream
-- remembers previously entered points where that makes sense.
--
-- Open question: how to maintain Sketchpad-style constraints? Answer for now:
-- we don't. Constraints operate only for the duration of a drawing operation.
-- We'll continue to persist them just to keep the option open to continue
-- solving for them. But for now, this is a program to create static drawings
-- once, and read them passively thereafter.
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
end
draw_pending_shape(12,line.y, line.pending)
function love.mousereleased(x,y, button)
if lines.current then
if lines.current.pending then
if lines.current.pending.mode == 'freehand' then
-- the last point added during update is good enough
elseif lines.current.pending.mode == 'line' then
lines.current.pending.x2 = coord(x-12)
lines.current.pending.y2 = coord(y-lines.current.y)
end
table.insert(lines.current.shapes, lines.current.pending)
lines.current.pending = {}
lines.current = nil
end
end
end
function draw_shape(left,top, shape)
if shape.mode == 'freehand' then
local prev = nil
for _,point in ipairs(shape.points) do
if prev then
love.graphics.line(pixels(prev.x)+left,pixels(prev.y)+top, pixels(point.x)+left,pixels(point.y)+top)
end
prev = point
end
elseif shape.mode == 'line' then
love.graphics.line(pixels(shape.x1)+left,pixels(shape.y1)+top, pixels(shape.x2)+left,pixels(shape.y2)+top)
end
end
function draw_pending_shape(left,top, shape)
if shape.mode == 'freehand' then
draw_shape(left,top, shape)
elseif shape.mode == 'line' then
love.graphics.line(pixels(line.pending.x1)+left,pixels(line.pending.y1)+top, love.mouse.getX(),love.mouse.getY())
end
end
function on_shape(x,y, shape)
if shape.mode == 'freehand' then
return on_freehand(x,y, shape)
elseif shape.mode == 'line' then
return on_line(x,y, shape)
else
assert(false)
end
end
-- turn a stroke into either a horizontal or vertical line
function convert_horvert(drawing, i, shape)
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}}
-- turn a line either horizontal or vertical
function convert_horvert(shape)
if shape.mode == 'freehand' then
convert_line(shape)
end
assert(shape.mode == 'line')
if math.abs(shape.x1-shape.x2) > math.abs(shape.y1-shape.y2) then
shape.y2 = shape.y1