Clojure2D is a library supporting generative coding or glitching. It’s based on Java2D directly. It’s Clojure only, no ClojureScript version.
Refactoring in progress -> towards 0.1.0, check Changelog.
This project is the answer to personal needs to optimize my own workflow for generative or glitch creations. I’ve been producing a lot of Processing code and started to suffer from limitations of working in ‘write sketch and run’ mode. Too much copy&paste between sketches, zillions of folders, zillions of processed images. And one day I fell in love with FP. This code is the answer.
What’s wrong with Processing?
- not reusable code - you have to copy your common parts between sketches
- display and canvas coupling
- weak or no support for parallelism
- more minor…
Is it replacement for…
… quil, thi.ng, clisk, possibly other?
No, rather no. The closest is quil, which is really great library (both Clojure and Clojurescript, great documentation and webpage, functional mode, 3d support etc.).
Clojure2d emphasises math, color and pixels operations and adds a lot of ready to use effects/filters (see
What’s special in this library then?
- Almost decoupled display and canvas (decoupled drawing and refreshing) - you can have as many windows as you want, you can have as many canvases as you want. Display repaints selected canvas automaticaly in separate thread. This way you can operate on canvas in your pace.
- Processing way is still possible (you can attach draw() function to your Display). However main benefit here: draw function keeps context between invocations, this way you can avoid global state (atoms etc.) and write more functional way. The same is for events, each Window has assigned state which is passed through event calls.
- Easy live coding possible (Emacs/Cider/REPL)
- FastMath as main math library
- Main focus on higher level generative/glitch concepts (like sonification support, vector field functions, colorspace operations, things like pixelsorting, slitscan etc. See my Processing sketches, link below)
Check out examples and results folders
It’s kind of personal library which supports my (probably not optimal, not convenient for others) way of creating stuff. There are still plenty of bugs and not idiomatic code. It may be slower than Processing. Eats a lot of memory (Pixels code is generally immutable). Still not stable API and architecture. No tests (yet)
Add following line as a dependency to your
Since still no tutorials are available, check out prepared examples. All namespaces are described below.
This is main namespace with functions in three groups:
- image file oparations (load/save); jpg, png and bmp
- canvas operations (wrapper for Java2D BufferedImage and Graphics2D)
- window and event operations (JFrame wrapper)
- global state (one per window)
- session handling (logger + unique, sequential filename generator)
Pixels type as a representation of channel values of the image plus operations on pixels. Defines also:
- pixel filters (blur, erode, dilate, median, threshold, posterize, tint)
- composing Pixels
- higher order functions which operate on Pixels parallelly (filter-channels, blend-channels)
- accumulation bins (smooth rendering canvas)
- colorspace converters
- collection of blending basic functions (like add, subtract, divide, difference, etc.)
- palette generation / color reducing filter
This is namespace for common generative/glitch specific libraries:
- signal - signal processing, wave generators, effects and filters (sonification enabler) docs
- overlays - 3 overlays (noise, spots and rgb scanlines) to finish your images docs
- segmentation - segment Pixels into rectangles docs
- variations - vector field functions / variations taken from fractal flames world docs
- glitch - glitching filters
- raymarching - simple ray marching 3d scene renderer
All math functions are in fastmath repository.
200+ examples are in separate repository
Marginalia docs + github.io page - in progress
- Cleaning, optimizations - still in progress (more profiling, boxed math removal)
Parallel color operations on Pixels Color namespace cleaning Colorspace converters
- More in extra ns:
- SDF objects
- glitch filters in extra namespace (moved from Processing)
- analog filters (for sonification part)
- More canvas drawing functions (PShape implementation - partially done)
Session handling (saving results in session, logging actions) - done, not tested
- Sanity tests
Low priority or ideas
- Cheat sheet
More window events
- Deeper joise bindings
- Wavelets bindings
- Tests… (in progress)
How to support
Yes! You can help with this project:
- create more variations
create colorspace converters
- create pixel filters
- create analog (audio) filters
- speed optimizations
- idiomatic clojure fixes
Discuss about it with me on Slack. Or just Pull Request.
Projects / links
- Processing glitch/generative projects
- Visual log
- Folds project
- Facebook 1
- Facebook 2
Copyright © 2016-2017 GenerateMe Distributed under the MIT Licence