Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0

Monday, 17 August 2009

Context Free Ruby Processing DSL

Here is my first go at writing context free rules in ruby (uses a library to support the DSL).


# shell_spiral.rb ruby-processing
load_library 'context_free'

def setup_the_shell
        @shell = ContextFree.define do
                rule :start do
                        shell_spiral :rotation => PI, :hue  => 41.1,
                        :sat => 0.573, :brightness => 0.9238, :alpha => 0.5
                end
                rule :shell_spiral do
                        circle
                        shell_spiral :rotation => -0.50, :x => 0.25,
                        :size => 0.9985
                end
        end
end


def setup
        size 1000, 1000
        setup_the_shell
        no_stroke
        color_mode HSB, 1.0
        smooth
        draw_it
end


def draw
        # Do nothing.
end


def draw_it
        background -1.0
        @shell.render :start, :size => height/50,  :stop_size => 1,
        :start_x => width/3, :start_y => height * 0.9  
end


def mouse_clicked
        draw_it
end


No comments:

Post a Comment

Followers

Blog Archive

About Me

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