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

Thursday, 25 April 2013

Understanding the ruby-processing examples (since processing-2.0 and ruby 1.9)

I've been pushing out a lot of ruby-processing samples, and suddenly realized that I should flesh out the reasons why some of the code looks the way it does:

  1. First of all, and this is very important for anyone looking at the older ruby-processing examples, all ruby-processing sketches should now be "bare sketches" (ie similar to what you might do in the processing ide the user does not explicitly wrap the code in class). However as with regular processing the code does get wrapped in a class at run time, with regular processing the class name is taken from the folder name, with ruby-processing it becomes the sketch class. I see this a good move, because it can be done, but also you might find that an explicitly wrapped sketch may not run, you have been warned.
  2. As with regular processing the default renderer is JAVA2D, but a change for ruby-processing since processing-2.0 the renderer SHOULD be defined as the third argument in "size", and preferably this is the first line in the "setup" block as with regular processing.
  3. When loading libraries, it is not usually sufficient to "load_library" or load_libraries" this should be followed by either import or include. If you want to include a java package I have preferred "include_package" over "java_import" (this is kosher since the Processing::App is a module). It is sometimes sensible to create your own module to facilitate the import of packages (outside of sketch file) the module will then act as "namespace" you can use to your advantage.
    module JavaUtil
      include_package "java.util"
    end
    
    JavaUtil::Date.new
    
  4. Since processing-2.0, I have found it necessary to explicitly "setVisible" the control_panel, which otherwise seems to work as expected (can't say I'm a big fan of the processing.event introduced in processing-2.0, and I had anticipated conflicts, but I've seen none so far), and certainly the use of reflection in "registerMethod" is just plain EVIL.

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