Generative Art Projects

draw-something sketch

A code sketch for draw-something. Yes this is really how I work. The comments will be turned into code, and may or may not be kept. Ideally they won’t, the code should be self-explanatory (stop laughing at the back).

;; Simple hierachical, loop-based figure drawing.

(defmethod draw-something ()
(let ((the-drawing (make-drawing)))
(until (drawing-finished? the-drawing)
(let ((drawing-bounds (find-space-for-figure drawing)))
(if drawing-bounds
(draw-figure the-drawing drawing-bounds))))))

(defmethod drawing-finished? ((the-drawing drawing))
;; Do we have some of everything?
;; Have we covered enough of the drawing?
;; Do we have to?: Has allocating space failed or too many attempts failed?

(defmethod enough-of-everything? ((the-drawing drawing))
;; Count the number of small, medium and large objects
;; Are they >= the required amount?

(defmethod drawing-coverage ((the-drawing drawing))
;; Iterate through all the figures
;; Add the area of their bounds
;; Divide 1.0 by the area of the drawing and multiply by the figure bounds sum

(defmethod draw-figure ((the-drawing drawing) (drawing-bounds rectangle))

(defmethod find-space-for-figure ((the-drawing drawing) (required-area real))
;; Step through x, y, step 10 units or whatever
;; If inside bounds of an existing figure continue
;; Grow the ltrb bounds of the box (start at 0 w/h) 1 step each direction,
;; stopping when each line hits a figure bounds or the drawing edge
;; Is it big enough for the requested area?
;; No? Continue.
;; Yes? Return it
;; Finished without finding a big enough space? Let the caller know