Imajen is a framework for procedural image generation. It allows you to render an image describe via functions. It is written in Clojure, and lets you use higher order functions (such as composition) to build your images from simple pieces.
Until Imajen is officially released, you must “manually” install it to your local Maven repository.
- Clone the repository:
git clone https://github.com/davisn/imajen.git
- Build and install with
lein install
Alternatively, you may use Leiningen to build a jar file
and add the jar file (along with all dependencies) to your classpath
.
To use Imajen, you must first ensure it is on your classpath. Using Leiningen, simply add the following to your project.clj dependencies:
[imajen "0.1.0-SNAPSHOT"]
Note: Because there is no official release yet, you must install Imajen first to your local Maven repository using the installation directions above.
First import the necessary imajen namespaces:
(use 'com.positronic-solutions.imajen)
(use 'com.positronic-solutions.imajen.view)
The quickest way to generate and view and image is via show-function
.
show-function
accepts a function and does the following:
- Create a
JFrame
containing aCanvas
- Create a
BufferedImage
to hold the generated image. This image has the same dimensions as theCanvas
. - Render the
BufferedImage
. The pixel values are determined by the value returned by applying the function to parametersx
andy
.x
andy
correspond to the pixel location, but are (independently) normalized over the domain[0,1]
. - Once the
BufferedImage
has been rendered, render the image to theCanvas
.
The following code illustrates how to render an image having constant color (blue):
(show-function (constantly [0 0 1]))
Of course, you will get more interesting results if you apply show-fuction
to a more interesting function.
You may use any function, as long as it obeys the following rules:
- The function must accept two arguments. These arguments will range from 0 to 1, and will correspond to the current pixel being rendered.
- The function must return a vector containing three elements. These elements must be numbers and should be in the range [0 1]. They correspond to (in order) the red, green, and blue values respectively of the pixel being rendered.
Imajen is currently in a pre-alpha development state. As a result, what little API exists at this point is subject to severe and incompatible changes. Documentation is virtually non-existant at this point.
However, Imajen is actively developed, so this will not be the situation forever.
Imajen is licensed under the GNU Lesser General Public License (LGPL).