Posts Tagged ‘clisk’

“There are only two hard things in Computer Science: cache invalidation and naming things (and off-by-one errors)”

Clojure is a great language, and one of the few things I dislike about coding in Clojure are namespaces.

It is not because namespaces are fundamentally a bad idea – in fact namespaces are a great feature and I believe they are fundamentally important if you are trying to manage a code base effectively.

But they are particularly fiddly to get right in Clojure. They cause a lot of unnecessary grief. They are not Simple. This is the story of my battle with the namespace demons to construct a decent namespace for Clisk live-coding.

(more…)

Advertisements

Planes and patterns

Posted: December 17, 2012 in enlight
Tags: , ,

Implemented some more functionality in Enlight – now we have infinite primitives to play with, starting off with planes:

Image

Still no lighting yet, as you can see. But that should be fairly easy to add once the core primitives and tracing functions are all working nicely.

All the textures are defined using Clisk functions, which has proved to be a very effective way to quickly generate 3D textures (all of the textures in the above scene were simple one-liners).

The scene itself is defined using a Scene Description Language, which is a DSL roughly based on the POVRay format translated into Clojure s-expressions. I’m not entirely happy with this yet, will probably go through a few iterations before I push out a finalised version. Defining a sphere currently looks roughly like this:


[:sphere [1 1 1] :radius 2 :colour [1 0 1]]

 

 

 

Enlight starts to emerge

Posted: December 13, 2012 in Uncategorized
Tags: , , ,

Spent a bit of time this weekend hacking on Enlight, my little Clojure raytracing project. Here’s one of the first outputs:

Image

 

 

(more…)

Creating a glow effect

Posted: October 4, 2012 in clisk, Uncategorized
Tags: , ,

Quick tutorial on how to create a “glow” effect for any image / shape in Clojure with Clisk.

Image

The idea behind the glow effect is to do the following:

  • Start with an image that has an alpha channel indicating which areas are transparent
  • Extract the alpha channel to get the pure shape of the object
  • Create a glow effect by applying a blur filter to the shape
  • Superimpose the original object on top of the glow

(more…)

Image filtering

Posted: October 1, 2012 in clisk
Tags: , , ,

Released clisk 0.4.4 with functionality to support image filters.

Example below:

(more…)

Mandelbrot fractals

Posted: August 30, 2012 in clisk
Tags: , , ,

I’ve added a new fractal generating function to Clisk. It’s pretty general purpose and can handle all kinds of iterative fractals.

Here’s the classic mandelbrot:

(show (viewport [-2 -1.5] [1 1.5]
  (fractal
    :while (v- 2 (length [x y]))
    :update (v+ c [(v- (v* x x) (v* y y)) (v* 2 x y)])
    :result (vplasma (v* 0.1 'i))
    :bailout-result black
    :max-iterations 1000)) 1024 1024)

Mandelbrot

I’m pretty happy with the little fractal DSL which is implemented using keyword arguments. You can control pretty much every aspect of the iterative procedure used to create the fractal. There are some handy shortcuts you can use in your formulae:

  • x, y, z, t – the current co-ordinates in space that gets updated in each iteration
  • pos – the current co-ordinate vector
  • c – the initial co-orinate vector (i.e. equal to pos on the first iteration)
  • ‘i – the iteration number. Note this is a symbol, I might make this into a function in the future for convenient to avoid the quote but you need it for now

For example, by tweaking the :result formula you can easily create some interesting fractal patterns:

(show (viewport [-2 -1.5] [1 1.5]
  (fractal
    :while (v- 2 (length [x y]))
    :update (v+ c [(v- (v* x x) (v* y y)) (v* 2 x y)])
    :result (v* (rgb-from-hsl [(v* 0.13 'i) 0.8 0.8])
                (scale 1.5 (checker black white)))
    :bailout-result black
    :max-iterations 1000)) 512 512)

Performance is also looking good – the image above took around 3secs to render on my machine. It’s amazing how much hardware has progressed – I still remember the days when I had to leave my Atari 800XL running overnight to get a low resolution mandelbrot image!

Voronoi stained glass

Posted: August 13, 2012 in Uncategorized
Tags:

Here’s a pretty image generated using Voronoi functions in Clisk ….

(more…)