Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DSL for Clojure image synthesis

I'm experimenting with creating a small library/DSL for image synthesis in Clojure. Basically the idea is to allow users of the library to compose sets of mathematical functions to procedurally create interesting images.

The functions need to operate on double values, and take the form of converting a location vector into a colour value, e.g. (x,y,z) - > (r,g,b,a)

However I'm facing a few interesting design decisions:

  • Inputs could have 1,2,3 or maybe even 4 dimensions (x,y,z plus time)
  • It would be good to provide vector maths operations (dot products, addition, multiplication etc.)
  • It would be valuable to compose functions with operations such as rotate, scale etc.
  • For performance reasons, it is important to use primitive double maths throughout (i.e. avoid creating boxed doubles in particular). So a function which needs to return red, green and blue components perhaps needs to become three separate functions which return the primitive red, green and blue values respectively.

Any ideas on how this kind of DSL can reasonably be achieved in Clojure (1.4 beta)?

like image 607
mikera Avatar asked May 15 '12 07:05

mikera


1 Answers

A look at the awesome ImageMagick tools http://www.imagemagick.org can give you an idea of what kind of operations would be expected from such a library.

Maybe you'll see that you won't need to drop down to vector math if you replicate the default IM toolset.

like image 50
StudioEvoque Avatar answered Sep 28 '22 01:09

StudioEvoque