Generative Art

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):


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
do (progn
(when (not (within-angular-limits))
(incf panic-count)
(when (> panic-count 20)
(setf sub-phase-count 0) ;; Start new phase
(loop-finish)) ;; This will still evaluate finally
(when (reached-destination)
(return-from stop)))
until (end-of-sub-phase)
finally (reverse-swing)))
until (end-of-phase))))