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

Tuesday 20 April 2010

Adding a custom terminal in ruby-processing context-free DSL

Here I describe how you can extend the ruby processing context free DSL. Previously I overrode the triangle method, but as Jeremy (Ashkenas) pointed out to me in a personal communication I could just as easily define a new terminal (this may lead to further experimentation).

load_library 'context_free'

def setup_the_spiral
  @spiral= ContextFree.define do
    ############ Begin defining custom terminal, an isoceles triangle    
    class << self    
      define_method(:isoceles) do |some_options# isoceles triangle
        size, options = *self.get_shape_values(some_options)
        rot = options[:rotation]
        rotate(rot) if rot
        super.triangle(-0.5 * size, -0.5 * size, -0.5 * size, 0.5 * size, 0.5 * size, 0.5 * size)
        rotate(-rot) if rot
      end
    end
    ########### End definition of custom terminal 'isoceles'
    rule :spiral do
      isoceles :brightness => -1, :rotation => 90
      spiral :rotation => 135, :size => 1/sqrt(2), :x => 1/sqrt(2)
    end
  end
end




I've added a white border using Gimp otherwise the image gets lost in my background.

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