Archive for the ‘clisk’ Category

“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

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!