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

Saturday, 24 April 2010

Moire patterns from custom bar shape Context free DSL


#########################
# donut.rb  inspired by Lekkere donut by marksmit
# uses a custom vbar terminal
#########################
load_library 'context_free'

def setup_the_moire
  @moire = ContextFree.define do
    ############ Begin defining custom terminal, a proportional vertical bar
    class << self  
      define_method(:vbar) do |some_options|
        size, options = *self.get_shape_values(some_options)
        w = some_options[:w]|| 0.1    # default vbar width is 0.1
        ratio = w * size
        rot = options[:rotation]
        rect_mode(CENTER)
        rotate(rot) if rot
        rect(-0.5 * ratio, -0.5 * size, 0.5 * ratio, 0.5 * size)
        rotate(-rot) if rot
      end
    end
    ########### End definition of custom terminal 'vbar'

    rule :donut do
      split do
      360.times do
        ring :brightness => 1, :rotation => 1
      end
      end
    end  

    rule :ring do
      rot = 2
      split do
      30.times do |i|
        element :brightness => 1, :rotation => rot * i
      rewind
      end
      end
    end
  
    rule :element do
      vbar :size => 10, :w => 0.005, :brightness => 1
    end
  end
end

def setup
  size 400, 400
  background 255, 255, 0
  smooth
  no_stroke
  setup_the_moire
  draw_it
end

def draw_it
  @moire.render :donut, :start_x => width/2, :start_y => height/2,
               :size => height/15, :stop_size => 1, :color => [0, 1, 1]
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