A Clojure library with simple utilities for creating generative artwork.
This library is built around Quil, a Clojure wrapper around the Processing framework. However, most of the functions are just mathematical utilies that could be used idependently.
To see and read about my artwork, visit tylerxhobbs.com or follow me on Instagram or Twitter.
To install, add this to your dependencies in project.clj
:
[genartlib "0.1.22"]
View the API Docs.
The genartlib library has the following tools:
Under project-template/, you'll find the basic setup that I use for every new generative art project. This is geared towards creating static images.
I also wrote a bit about my development setup and how I use it.
The following algebra-ish functions are defined:
avg
- averageinterpolate
/ interpolate-multi
- linear interpolationrescale
- map from one range to anotherline-intersection
- find the intersection of two lineslines-intersection-point
- another way to find line intersectionsslope
/ point-slope
- get the slope of a liney-intercept
- get the y intercept point of a lineangle
/ point-angle
- get the angle between two points in radiansangular-coords
- calculate the offset location from a base point with angle and magnitudepoint-dist
- distance between two pointspoint-to-line-dist
- distance from a point to a linepolygon-contains-point?
- a fast test for checking if a point falls inside a polygonrotate-polygon
- rotates around the average center of the polyshrink-polygon
- shrink by a ratiochaikin-curve
- a curve-smoothing algorithmchaikin-curve-retain-ends
- a variation that preserves the original end pointscurve-length
- calculate the total length of a curvesplit-curve-with-step
- break up a curve into chunks with the given lengthsplit-curve-into-parts
- break up a curve into chunks with equal length, given a number of parts to haveinterpolate-curve
- find a point that is a given percentage along the length of a curveline-simplification
- an implementation of the Ramer-Douglas-Peucker line simplification algorithmtrim-curve-to-bounds
- returns a seq of sub-curves that are entirely within the bounds of the imagetrim-curve-start
- removes the specified length from the start of a curvetrim-curve-end
- removes the specified length from the end of a curvegauss
- sample a gaussian probability distributionabs-gauss
- basically shorthand for (abs (gauss ....))
gauss-range
- returns a seq of integers from zero to a value sampled from a Guassian distributiontriangular
- sample a triangular probability distributionsimple-triangular
- like triangular
, but assumes a = 0 and b = cpareto-sampler
/ pareto-sample
- sample a pareto probability distributionrandom-point-in-circle
- uniform sampling of points within a circleodds
- returns true or false with the given probabilitychoice
- pick from a list of items with uniform probabilityweighted-choice
- pick from a list of items, each with an assigned probabilityrepeatable-shuffle
- a version of shuffle that uses Processing's Random, in order to ensure repeatability with the same seedsort-curves-for-plotting
- sorts a seq of curves in order to minimize plotter travel distanceThis namespace contains a set of macros that are useful for capturing draw operations in a sketch, and recording them (or translating) them to another format, such as an SVG that is suitable for plotting. The nice part is that the sketch will still function as normal.
with-plotter-svg-capture
- create an svg file representing all line and shape operations that is suitable for plotting with an Axidraw. Note that Processing functions other than these two (e.g. ellipse, or bezier curves, or transformations) are not yet supported and are ignored.with-command-capture
- captures many draw operations in an EDN format that is easy to manipulate with Clojurecommand-replay
/command-replay-file
- replays the results of with-command-capture
w
and h
- shorthand for expressing a length or position in terms of percentage of the image width or height - good for using a pseudo-vector approach to creating imagespi
- shorthand for (* Math.PI value)
set-color-mode
- set the color mode to HSV with ranges H [0, 360], S [0.0, 100.0], V [0.0, 100.0], alpha [0.0, 1.0]in?
/ not-in?
- test if a seq contains an itembetween?
- is a value inside an inclusive range?enumerate
- turns a seq of items into a seq like ([0 item-0] [1 item-1] [2 item-2] ...)zip
- combine two or more seqs into tuplessnap-to
- snap a value to a given window size, kind of like configurable roundingvec-remove
- remove an item from a vectordistinct-key
- given a function f to uniquely identify items, extracts all of the distinct values in a collectionCopyright © Tyler Hobbs
Distributed under the MIT License.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close