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

Thursday 4 September 2014

New features in ruby-processing-2.6.2

# Hooky class demonstrates how to use the post_initialize hook,
# available since ruby-processing-2.6.2, to add additional attribute
# in this case :background as an array of int (splat to color)
# Not sure how clever it is to have multiple sketch instances.

class Hooky < Processing::App
  attr_reader :back

  def setup
    size 200, 200
    background(*back)
  end

  def post_initialize(args)
    @back = (args[:background])
  end
end

red = [200, 0, 0]
green = [0, 200, 0]
blue = [0, 0, 200]
colors = [red, green, blue]

colors.each_with_index do |col, i|
  Hooky.new(x: i * 90, y: i * 90, title: "Hooky #{i}", background: col)
end


Read more about post-initialization hooks in POODR by Sandi Metz.

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