Random Colors, Color Pools, and Dual Mersenne Twister Goodness.

I’ve implemented a random color scheme in Structure Synth, using a new ‘color random’ specifier.

But what exactly is a random color? My first attempt was to use the HSV color model and choose a random hue, with full brightness and saturation.

This produces colors like this:

Most of my Nabla pictures used this color scheme. It produces some very strong colors.

Then I tried the RGB model using 3 random numbers, one for each color-channel, which creates this kind of colors:

But what about greyscale colors:

I decided that it was necessary to be able to switch between different color schemes.

So I created a new ‘set colorpool’ command. Besides the color schemes above (‘set colorpool randomhue’, ‘set colorpool randomrgb’, and ‘set colorpool greyscale’) I created two additional color schemes:

One where you specify a list of colors:

(For this image the command was: “set colorpool list:orange,white,white,white,white,white,white,grey”. As is evident it is possible to repeat a given color, to emphasize its occurrence in the image.)

And on where you specify an image which is used to sample colors from:

The command used for the above image was: “set colorpool image:001.PNG”. Whenever a random color is requested (by the ‘random color’ operator), the program will sample a random point from the specified image and use the color of this pixel. This is a quite powerful command, making it possible to imitate the color tonality of another picture.

Now this is all good. But I realized that there are some problems with this approach.

The problem is that geometry and the colors draw numbers from the same random number generator (the C-standard library ‘rand()’ function).

This means that changing the color scheme changes the geometry (since the color schemes use a different number of random numbers for each color – randomhue uses 1 random number per color, the image sampling uses two (X and Y) random numbers per color, the randomrgb uses three).

This is not acceptable, since you’ll want to change the color schemes without changing the geometry. Another problem is that C-standard library ‘rand’ function is not platform independent – so even if you specify a EisenScript together with an initial random seed, you will not get the same structure on different platforms.

I solved this by implementing new random generators in Structure Synth. I now use two independent Mersenne Twister random number generators, so that I have two random streams – one for geometry and one for colors.

8 thoughts on “Random Colors, Color Pools, and Dual Mersenne Twister Goodness.

  1. Well, if you compile it yourself, it can be tested as of now ­čÖé – The changes are in the Subversion repository.

    Otherwise, I plan to make a minor release of Structure Synth (v0.9.5) next week, which includes the new features.

  2. Wow, this really looks nice! Lookin’ forward to 0.9.5!

    any chance of getting a look on the ES for the example scene you used? It looks so random ­čÖé



  3. Hi saw0, sorry but your post ended up in my spam-filter – but here is the EisenScript:

    // 31 ,47, 51, 59

    // City: seed 70

    set maxdepth 40
    //set maxsize 10
    set colorpool randomrgb
    set colorpool list:orange,white,white,white,white,white,white,grey
    // Camera settings. Place these before first rule call.

    10 * { y 10 } 10 * { x 10 } 1 * { ry -90 b 0.2 } R1
    set background black
    { x 30 y 30 z 3 s 200 200 1 color random } box

    Rule R1 {
    //set seed initial
    { z 0.6 rx 5 } R1

    Rule R1 {
    { z 0.5 rx -90 } R1

    Rule R1 {
    { z 0.6 rz 90 } R1

    Rule R1 {
    { z 0.6 rz -90 } R1

    Rule R1 weight 0.01 {


    Rule dbox {
    { color random s 2 2 0.5 } box

    Rule dbox weight 0.5 {
    { ry 90 s 0.5 1 1 } R1

    Rule dbox weight 0.5 {
    { rx 90 s 0.5 2 1 } R1

  4. Hi I have a question. When I use “set seed” I have the same geometry.I would like to have the same geometry but different color always when I click build.It would be wonderfull if it will be possible. looking forward your reply

  5. Hi Alex, sorry for the late reply, but I’m been away on vacation.

    I’m afraid you cannot set the color seed individually – you best option is to change the color scheme.

    Best regards, Mikael.

Leave a Reply

Your email address will not be published. Required fields are marked *