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

Thursday 27 August 2009

Adjusting your context free DSL variables

It is possible using the control panel of ruby processing (a separate window see below)
to adjust your variables interactively. Some on the fly such as resolution (placed within draw), or others built into the rules via a re-run (via some button or "mouse-click"). Here is my proof of concept example, where by changing the triangle constants you can ruin your Sierpinski triangle. Or in this achieve a fantastic transition from a Sierpinski triangle to the 'y' of my previous post, might be worthy of an animation? This is an interactive animation updates as you move the slider (patience there is bit of calculation to be done). For 'y' set slider to 0.5 for Sierpinski set the slider to 1.


load_library 'context_free', 'control_panel'

attr_accessor :factor
T_HEIGHT = Math.sqrt(3)/2 # triangle height
BOTTOM = Math.sqrt(3)/6

def setup_the_triangle factor
    @triangle = ContextFree.define do
    rule :tri do
      triangle :alpha => 0.5
      split do
        tri :size => 0.5,  :y => (BOTTOM - T_HEIGHT) * factor, :x => 0, :brightness => 0.8
        rewind
        tri :size => 0.5, :y => BOTTOM * factor, :x => -0.5 * factor, :brightness => 0.8
        rewind
        tri :size => 0.5, :y => BOTTOM * factor, :x => 0.5 * factor, :brightness => 0.8
      end
    end  
  end
end

def setup
  size 600, 600
  no_stroke
  color_mode HSB, 1.0
  smooth
  @factor = 1
  control_panel do |p|
    p.slider :factor, (0.4...2), 1
  end
end

def draw
  background 255, 255, 0
  setup_the_triangle @factor
  @triangle.render :tri, :size => height/1.1, :stop_size => 3.0, :start_y => height/1.65
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