snek is a simple data structure for working with vertices and edges. More
importantly it is a programming pattern for applying changes to the structure.
It is specifically written to be useful for a broad range of ways in which I
usually write generative algorithms for creating art.
A while back someone on twitter suggested that if Python 3 was named "snek" it would avoid naming confusion. I found that amusing at the time, and picked snek as the placeholder name for this project. I've been looking for a better name, but I haven't found one yet.
The pattern depends on the concept of alterations. In short: an alteration
is a change that will be applied to the structure at the end of a given
context. alterations are further described in
http://inconvergent.net/snek-is-not-an-acronym/.
I have also written about things related to snek at
- http://inconvergent.net/a-propensity-for-mistakes/ (indirectly about
snek) - http://inconvergent.net/a-method-for-mistakes/
- http://inconvergent.net/arbitrary-alterations/
Here is and example of manipulating a snek instance called snk using
alterations. Alteration constructors are postfixed with ?.
; context start
(with-snek (snk)
; iterate vertices
(itr-verts (snk v)
; move alteration
(move-vert? v (rnd:in-circ))
; w will be an arbitrary
; vertex in snk
(with-rnd-vert (snk w)
; join v and w if they are closer than d
(if (< (edge-length snk (list v w)) d)
; join vertices alteration
(join-verts? v w))))
; context end
; alterations have been appliedYou can define your own arbitrary alterations. There is an example of this in
ex-custom-alt.lisp. I have also written about it here:
http://inconvergent.net/arbitrary-alterations/
There are some examples included. They can be executed like this:
./ex-slope.lisp res/slope
./ex-lines.lisp res/lines
./ex-grp.lisp res/grp
./ex-custom-alt.lisp res/custom
./ex-hyphae.lisp res/hyphae
There is also and example of how to use the plotting functionality. This will export a simple vector file and an image to indicate the result
./ex-plot-perspective.lisp res/perspective
Notice that the resulting image will end up in res.
snek is used in
- http://moment.inconvergent.net/
- https://twitter.com/sandpaintbot
- https://twitter.com/scratchpaintbot
- https://twitter.com/cronianrings
This code requires Quicklisp and zpng. The path to quicklisp must be set in
src/load. zpng is automatically installed via quicklisp.
There are some tests included. Run them like this:
./test.lisp
./test-snek.lisp
This code is highly experimental on my part. It is likely to change with no
warning or explanation. I will keep a note of the version number in VERSION.
This code is a tool that I have written for my own use. I release it publicly in case people find it useful. It is not however intended as a collaboration/Open Source project. As such I am unlikely to accept PRs, reply to issues, or take requests.
- math utils as package?
- snek as package?
- Randomized order of alteration apply
- Maintain list of singly-connected vertices?

