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 processing.py

Tuesday, 11 August 2009

Recursion is key to Context Free

I wasn't super happy with resorting to PATH to create my nautilus object (previous post) but I was having difficulty getting to grips with the cfdg grammar. Mountain View Mark was only to pleased to put me right, but his original rules confused the issue a bit (I thought there was a spurious z number, turns out that it can be used to force one layer behind another, quite deep in the documentation kipling put me right on that, NB you should check out some of kiplings creations) I have re-written Marks rules to keep my original primary colors/brightness/saturation, and with my preferred shape names. But the most significant thing that hits you is the recursion, he came up with the size and displacement numbers empirically. There is some underlying math as a result of the recursion, I think it might be nice to derive those numbers mathematically. Here is the modified code:-
   1 startshape nautilus
2 background {b -1}
3 rule nautilus{
4 shell { r -20 hue 360 sat 1 b 1 }
5 septa { r -20 hue 220 sat 1 b 1 }
6 }
7
8 rule shell {
9 CIRCLE { }
10 shell { r 0.50 x 0.25 size 0.9985 }
11 }
12
13 rule septa {
14 divider { r 30 }
15 septa { r 50.5 size 0.859 x 20.7 y 9.3 }
16 }
17
18 rule divider {
19 485 * { r 0.15 x 0.05 size 0.9999 }
20 CIRCLE { size .2 }
21 }

And here is the result which is quite satisfying, with the width of the shell increasing in a natural way (except the way cfdg works it is decreasing in a natural way, infinite recursion is terminated when the size of an element (circle here) falls below a certain value), something that my 'processing' version did not do, I might take a look at that code to and see what I can do there. Also for once there is a bonus in my jedit highlighting mode being unable to differentiate between a size directive and a size as in scale, the blue highlighting makes it really stand out!!!


I experimented with these rules by first removing the rotation from the shell rule, what this does is to essentially unwind the shell spiral. So the size adjustment doesn't seem so be so important (other than to kill the infinite recursion), however on further experimentation using a constant size CIRCLE you only get a circle not the spiral, so you do need all three adjustments:-

   1 startshape nautilus
2 background {b -1}
3 rule nautilus{
4 shell { r -20 hue 360 sat 1 b 1 }
5 septa { r -20 hue 220 sat 1 b 1 }
6 }
7
8 rule shell {
9 CIRCLE { }
10 shell { x 0.25 size 0.9985 }
11 }
12
13 rule septa {
14 divider { r 30 }
15 septa { r 50.5 size 0.859 x 20.7 y 9.3 }
16 }
17
18 rule divider {
19 485 * { r 0.15 x 0.05 size 0.9999 }
20 CIRCLE { size .2 }
21 }



Rule modified to give constant shell thickness (with low probability rule to prevent inifinite recursion

   1 startshape nautilus
2 background {b -1}
3 rule nautilus{
4 shell { r -20 hue 360 sat 1 b 1 }
5 septa { r -20 hue 220 sat 1 b 1 }
6 }
7
8 rule shell 0.001 {} // empty rule to prevent infinite recursion
9
10 rule shell {
11 CIRCLE { }
12 shell { r 0.5 x 0.25 }
13 }
14
15 rule septa {
16 divider { r 30 }
17 septa { r 50.5 size 0.859 x 20.7 y 9.3 }
18 }
19
20 rule divider {
21 485 * { r 0.15 x 0.05 size 0.9999 }
22 CIRCLE { size .2 }
23 }


2 comments:

  1. Glad you like it, I can't take much credit for it though, plenty more impressive stuff to be found over at the context free gallery.

    ReplyDelete

Followers

Blog Archive

About Me

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