Skip to content

Java2D wrapper + creative coding supporting functions (based on Processing and openFrameworks)

License

Notifications You must be signed in to change notification settings

Joshua8Lack/clojure2d

 
 

Repository files navigation

clojure2d

Clojure2D is a lightweight library supporting generative coding or glitching. It's based on Java2D directly. It's Clojure only, no ClojureScript version.

ex10 ex21 ex5

ex11 ex16 ex19

ex22 ex23

Documentation

Github.io

Marginalia - In progress!

Codox - In progress!

Motivation

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...

Why not use...

... quil, thi.ng, clisk, possibly other?

The main reason was that I wanted to learn Clojure making something from the scratch. Quil is still Processing. Thi.ng was to complex to me at the beginning (but I plan to investigate what can be usable).

What's special in this library then?

In points:

  • 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), 'notebook' way of making
  • 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

What's odd?

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)

Installation

Add following line as a dependency to your project.clj

[clojure2d "0.0.4-SNAPSHOT"]

Usage

Since still no docs are available, check out prepared examples. All available packages are described below.

clojure2d.core docs

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)
  • display and event operations (JFrame wrapper)
  • session handling (logger + unique, sequential filename generator)

clojure2d.pixels docs

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)
  • blending (composing) function of two Pixels
  • functions which operate on Pixels parallelly (filter-channels, blend-channels)
  • accumulation bins (smooth rendering helper)

clojure2d.color docs

  • colorspace converters
  • collection of blending basic functions (like add, subtract, divide, difference, etc.)
  • palette generation / color reducing filter

clojure2d.math docs

  • FastMath (jafama) bindings
  • statistic functions

Additionally in following namespaces:

  • clojure2d.math.complex - Complex (Vec2) operations (code taken from Apache Commons Math) docs
  • clojure2d.math.vector - Vec2, Vec3 and Vec4 types and operations on vectors docs
  • clojure2d.math.joise - Joise library bindings (basic (simplex/perlin/value), cell (voronoi) and fractal noise + combinations) docs
  • clojure2d.math.random - Random functions and perlin noise from flow-noise library docs

clojure2d.extra

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

Examples

I've prepared several examples with results where you can check current state of the library and learn how it works.

TODO

High priority

  • Marginalia docs + github.io page - in progress
  • Cleaning, optimizations - still in progress (more profiling, boxed math)
  • Parallel color operations on Pixels
  • Color namespace cleaning
  • Colorspace converters
  • More in extra ns:
    • SDF objects
    • variations
    • glitch filters in extra namespace (moved from Processing)
    • analog filters (for sonification part)
  • 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...

Community

Clojurians

How to support

Yes! You can help with this project:

  • Beginners:
    • create more variations
    • create colorspace converters
    • create pixel filters
    • create analog (audio) filters
  • Advanced:
    • speed optimizations
    • idiomatic clojure fixes

Discuss about it with me on Slack. Or just Pull Request.

Projects / links

License

Copyright © 2016-2017 GenerateMe Distributed under the MIT Licence

About

Java2D wrapper + creative coding supporting functions (based on Processing and openFrameworks)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Clojure 99.4%
  • Other 0.6%