Created
May 20, 2017 00:26
-
-
Save lispm/b4fad77dd6f7fa50f9985af5554e4f9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun hyphae (sand size fn itt rad mid) | |
(let ((curr (make-hash-table :test #'equal)) | |
(hits 0)) | |
(labels ((init (snk n) | |
(loop for i from 0 below n do | |
(setf (gethash | |
(add-vert! snk (rnd-in-box 250 250 :xy '(250 250))) | |
curr) | |
0))) | |
(circ-stroke (vv) | |
(sandpaint:circ sand | |
(lin-path:pos* (lin-path:make vv) (linspace 0 0.99 100)) | |
1 20)) | |
(draw (snk a w) | |
(sandpaint:set-rgba sand (list 0.0 0.7 0.7 0.01)) | |
(sandpaint:circ sand (list (append-edge-alt-xy a)) 4 3000) | |
(sandpaint:set-rgba sand (list 0.0 0.0 0.0 0.01)) | |
(circ-stroke (get-verts snk (list w (append-edge-alt-v a))))) | |
(count-control (v) | |
(multiple-value-bind (c exists) | |
(gethash v curr) | |
(if exists | |
(if (> c 20) | |
(print (remhash v curr)) | |
(incf (gethash v curr)))))) | |
(do-append-edge-alt* (snk a) | |
(let ((v (append-edge-alt-v a))) | |
(count-control v) | |
(inside (size (append-edge-alt-xy a)) | |
(if (<= (length (verts-in-rad snk (append-edge-alt-xy a) rad)) 1) | |
(aif (do-append-edge-alt snk a) | |
(progn | |
(incf hits) | |
(setf (gethash it curr) 0) | |
(draw snk a it)))))))) | |
(let ((snk (make-snek | |
:max-verts itt | |
:max-grp-edges 0 | |
:max-main-grp-edges (* 4 itt) | |
:alts '((append-edge-alt do-append-edge-alt*))))) | |
(init snk 20) | |
(loop for i from 0 below itt do | |
(with-snek (snk :zwidth rad) | |
(loop for k being the hash-keys in curr | |
collect | |
(append-edge? k | |
(add (get-vert snk k) | |
(rnd-in-circ rad)) | |
:rel nil)) | |
(sandpaint:save sand (format nil "~a-~6,'0d" fn hits)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment