Recently I've been looking at Povray, pyprocessing, and cfdg (version 3.0) as tools for creating digital images. I have branched two separate blogs where I mainly explore jruby + processing and

Thursday, 9 July 2009

Random Starfield Using CFDG

Here is some rule set that I copied that I can't attribute, because I lost the url, basically the original was producing black circles on a white background, and then inverting the image to produce the desired light stars, using photoshop (WHY?) and then copying the image onto itself to get more stars (WHY?).
Here I have used a loop to create more stars, and originally specified a black background with bright stars (code revised 10 July 2009).
Also the original had crazy names like PLANT for starfield, so I guess the code had already been hacked from some other project? PS if you want to combine cfdg images within gimp (or photoshop if you must) then why not create a transparent background layer line 2 would be background {a -1}, ie no alpha layer. When I did this I found out that I had inadvertently created some black stars, which could easily be corrected using an image manipulation program. However I think I have corrected this now. Originally I put brightness directive in my loop, now it is placed in CIRCLE terminal, empty directive in loop seems OK (any y or x adjustment here would destroy randomness). Whilst I was at it I changed the background from black to dark blue (I've still got a lot to learn).
   1:startshape starfield
2:background{hue 240 b -0.9 sat 1} // dark blue background
3:rule starfield{ // 5 times create white stars
4:5*{}either{x 2} // empty directive seems OK
6:// create two instances of star rotate both and flip one
7:rule both{
8:star{rotate 30}
9:star{rotate -30 flip 90}
11:// multiple either, create a star
12:rule either{
15:// or create a star and flip it
16:rule either{
17:star{flip 90}
19:// base star is a translated circle
20:rule star {
21:CIRCLE{b 1} // set star brightness at terminal seems to be safer
22:translate{size 0.91 y 24.6}
24:// multiple translate rules adds more randomness
25:rule translate {star {rotate 126}}
26:rule translate {
27:star{rotate 127}
29:rule translate {both{}}
30:rule translate {star {rotate -110 flip 90}}

A Random Starfield Image

The use of the either & both as names of rules seems to be a common idiom within cfdg. Combinations of these rules produce much randomness. I suppose an alternative would be to use 'branch & fork', instead of 'either & both', in keeping with conceptualizing the rules as tree of options? Funny how a lot of the art ends up describing a tree or a spiral (might be nice to a spiral twist to the starfield).


  1. The output looks a lot like star clusters through a telescope!

  2. The beauty of CFDG is that you could scale up the image as big as you wanted,
    in this case you would need to increase the value of y line 22. On second thoughts I should check out what the svg output looks like first (as that ought be v. scalable).

  3. The svg output was rubbish, however doubling the value of y and specifying -w 1280 -h 1024 (which corresponds to my screens resolution) produced a half decent result in png mode.
    I think the issue with the svg might be something to do with the rendering of white shapes on a white background, when I examined the file using inkscape the stars were there but sans background.



Blog Archive

About Me

My photo
Pembrokeshire, United Kingdom
I have developed JRubyArt and propane new versions of ruby-processing for JRuby- and processing-3.2.2