Since I'm a fan of contextfreeart.org and nodebox.net, I've made a small ruby program inspired by contextfreeart, using context free grammars in 3d with opengl. The only operations right now are:
- cube - create a cube.
- up/down/left/right/to/from(rule) - define what rule to continue with in the specified direction.
- flip - rotate 90 degress
- scale - scale with 0.9.
But it should be quite easy to add new primitives (and clean up the code). Here is an example of a tree. Install ruby-opengl gem, click and move mouse to rotate, q - new random seed value, w - increase rendering depth, e - decrease rendering depth.
load 'cfa3d.rb'
class Tree < CFG
rule :start do |s|
s.cube
s.up :x
end
rule :x do |s|
s.cube
s.right :x
end
rule :x do |s|
s.cube
s.flip
s.left :x
end
rule :x, 0.1 do |s|
s.cube
s.flip
s.right :x
s.flip
s.left :x
end
rule :x do |s|
s.cube
s.scale
s.up :x
end
end
render Tree