On Purpose Line

What seemed to be a problematic edge case in my implementation of the line drawing algorithm from Harold Cohen’s old essay “On Purpose” turned out to need a fundamental rewrite of much of the code (!) and I’m still not done. But I can now get results like this (with green lines for debugging):

cells.png

Here’s the main loop, structured to look like the flowchart from the essay:


(defun draw-line (from to)
(set-line-drawing-parameters from to)
(loop named stop
do (loop
initially (set-swing-left-or-right)
initially (setf panic-count 0)
do (progn
(set-length-of-sub-phase)
(set-rate-of-swing)
(loop
do (progn
(calculate-new-direction-for-line)
(when (not (within-angular-limits))
(incf panic-count)
(when (> panic-count 20)
(break))
(setf sub-phase-count 0) ;; Start new phase
(loop-finish)) ;; This will still evaluate finally
(correction-for-homing)
(calculate-position-of-next-point)
(move-to-next-point)
(when (reached-destination)
(return-from stop)))
until (end-of-sub-phase)
finally (reverse-swing)))
until (end-of-phase))))

Posted in Generative Art