rob-art

I’ve made the source code for draw-something more readable and modular, ready for the next round of development. So code that read like this:

(defmethod draw-around ((poly polyline) (han hand)) "Draw around a polygon using a hand." (let* ((the-hand (start-drawing poly han)) (first-point (location han)) (sketch (list first-point))) ;;Make the rest, finishing when < step from the original point (loop (let ((next-point (draw-step poly the-hand))) (setf sketch (cons next-point sketch)) ;; If the list is longer than two segments (1.2.nil) ;; And the current point is passing close to the first point (when (and (> (length sketch) 2) (< (distance next-point first-point) (speed han))) ;; Close the path... ;;REVISITME: This is too perfect... (setf sketch (cons first-point sketch)) ;; Returns from the enclosing block, not the function! (return nil)))) sketch))

now reads more like this (in part):

(defmethod ensure-next-pen-close-enough ((poly polyline) (p pen)) "If the pen would move too far next time, turn it right until it wouldn't." (while (next-pen-too-far poly p) (turn-right p (turn-step p)))) (defmethod adjust-next-pen ((poly polyline) (p pen)) "Set the pen back on the correct path around the shape." (ensure-next-pen-far-enough poly p) (ensure-next-pen-close-enough poly p)) (defmethod draw-step ((poly polyline) (p pen)) "Find the next point forward along the drawn outline of the shape." (adjust-next-pen poly p) (move-forward p (speed p)) (location p))

Which is much easier to understand and work with. Next up is a "probabilistic pen" if I can get that to work, and a simple colouring algorithm.

Posted in Projects