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

Tuesday 10 November 2009

Flower in ruby-processing DSL

# flower.rb ruby-processing
load_library 'context_free'
 

ROT = 180*(Math.sqrt(5) - 1)
 

def setup_the_flower
  @flower = ContextFree.define do
    @rot = 0
    @pet = 0
    rule :start do
      flower :brightness => 1.0
    end
 

    rule :flower do
      @rot += ROT
      @rot = @rot % 360
      split do
        petal :brightness => 1.0, :saturation =>  0.5
      rewind
        flower :rotation => @rot, :size =>  0.99, :hue =>  0.15
      rewind
      end
    end
  
    rule :petal do
      @pet += 15
      split do
        triangle :x => 4.1, :rotation => @pet
      rewind
        petal :size => 0.995, :alpha => 0.4, :brightness => 0.5
      #rewind
      end
    end
  end
end
  
def setup
  size 800, 800
  setup_the_flower
  smooth
  draw_it
  save_frame("flower.png")
end


def draw
  # Do nothing.
end


def draw_it
  background 60, 0, 0
  @flower.render :start, :size => width*0.8, :stop_size => 2,
        :start_x => width/2, :start_y => height/2
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