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

Wednesday 12 December 2012

Fix for ruby-processing context free

The adoption of jruby-1.7.0 for the latest version of processing has required changes to the context_free.rb script. See the change on my Pembrokeshire Branch. My dragon sketch and city sketches working fine, I haven't checked any other. Here is my dragon sketch updated to ruby-1.9 syntax (NB: continues work with 1.8 syntax)



# contributed by monkstone

load_library 'context_free'

def setup_the_dragon
  @dragon = ContextFree.define do

    rule :start do
      dragon alpha: 1
    end

    rule :dragon do
      square hue: 0, brightness: 0, saturation: 1, alpha: 0.02
      split do
        dragon size: 1/Math.sqrt(2), rotation: -45, x: 0.25, y: 0.25
        rewind
        dragon size: 1/Math.sqrt(2), rotation: 135, x: 0.25, y: 0.25
        rewind
      end
    end

  end
end

def setup
  size 800, 500
  setup_the_dragon
  smooth
  draw_it
end

def draw
  # Do nothing.
end

def draw_it
  background 255
  @dragon.render :start, size: width*0.8,  stop_size: 2,
                         start_x: width/3, start_y: height/3.5
end




















Here's a sketch with a simple custom shape of an isosceles triangle
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
        $app.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

def setup
  size 800, 500
  setup_the_spiral
  draw_it
end

def draw
  # Do nothing.
end

def draw_it
  background 255
  @spiral.render :spiral, size: height, start_x: width/3, 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