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

Wednesday, 16 June 2010

Cesàro fractal using ruby processing context free DSL.

Approximate Cesàro fractal loosely based on mariojan C++ version.

load_library 'context_free'


def setup_the_triangle

  @triangle = ContextFree.define do
    class << self
      define_method(:wedge) do |some_options# thin triangle
        size, options = *get_shape_values(some_options)
        rot = options[:rotation]
        rotate(rot) if rot    
        super.triangle(-0.03 * size, 0, 0, -size, 0.03 * size, 0)
        rotate(-rot) if rot
      end
    end

    rule :tri do
      wedge :y => -0.5
      split do    
        [90, -90, 180, 0].each do |rot|    
        rewind
        tri :y => 0.66667, :rotation => rot, :size => 0.5, :set_brightness => 1, :set_saturation => 1, :set_alpha => 1
        rewind
      end
      end
    end

    rule :four do
      split do
      4.times do |i|
        split do
        tri :rotation => 90 * i
      rewind
      end
      end
      end
    end

    rule :cesaro do
      four :rotation => 45
    end
  end
end

def setup
  size 400, 400
  setup_the_triangle
  no_stroke
  color_mode HSB, 1.0
  smooth
  draw_it
end

def draw_it
  background 0, 0.1, 0.1, 1.0
  @triangle.render :cesaro, :size => height * 1.05, :stop_size => 3, :start_y => height/2, :start_x => width/2, :color => [0, 0.8, 0.8, 0.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