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 = nilfor _,point in ipairs(line.pending) doif prev thenlove.graphics.line(pixels(prev.x)+12,pixels(prev.y)+line.y, pixels(point.x)+12,pixels(point.y)+line.y)endprev = pointend
draw_pending_shape(12,line.y, line.pending)
function love.mousereleased(x,y, button)if lines.current thenif lines.current.pending thenif lines.current.pending.mode == 'freehand' then-- the last point added during update is good enoughelseif lines.current.pending.mode == 'line' thenlines.current.pending.x2 = coord(x-12)lines.current.pending.y2 = coord(y-lines.current.y)endtable.insert(lines.current.shapes, lines.current.pending)lines.current.pending = {}lines.current = nilendendend
function draw_shape(left,top, shape)if shape.mode == 'freehand' thenlocal prev = nilfor _,point in ipairs(shape.points) doif prev thenlove.graphics.line(pixels(prev.x)+left,pixels(prev.y)+top, pixels(point.x)+left,pixels(point.y)+top)endprev = pointendelseif shape.mode == 'line' thenlove.graphics.line(pixels(shape.x1)+left,pixels(shape.y1)+top, pixels(shape.x2)+left,pixels(shape.y2)+top)endendfunction draw_pending_shape(left,top, shape)if shape.mode == 'freehand' thendraw_shape(left,top, shape)elseif shape.mode == 'line' thenlove.graphics.line(pixels(line.pending.x1)+left,pixels(line.pending.y1)+top, love.mouse.getX(),love.mouse.getY())endendfunction on_shape(x,y, shape)if shape.mode == 'freehand' thenreturn on_freehand(x,y, shape)elseif shape.mode == 'line' thenreturn on_line(x,y, shape)elseassert(false)endend
-- turn a stroke into either a horizontal or vertical linefunction convert_horvert(drawing, i, shape)local x1,y1 = shape[1].x, shape[1].ylocal x2,y2 = shape[#shape].x, shape[#shape].yif math.abs(x1-x2) > math.abs(y1-y2) thendrawing.shapes[i] = {{x=x1, y=y1}, {x=x2, y=y1}}
-- turn a line either horizontal or verticalfunction convert_horvert(shape)if shape.mode == 'freehand' thenconvert_line(shape)endassert(shape.mode == 'line')if math.abs(shape.x1-shape.x2) > math.abs(shape.y1-shape.y2) thenshape.y2 = shape.y1