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

Tuesday, 28 April 2015

Exploring the latest processing-3.0 with JRubyArt (with some success)

I have created a processing-3.0 branch to explore using the latest processing with JRubyArt and it is looking pretty good so far, JAVA2D was easy to get running but P2D and P3D modes took a bit longer. The key to running in the opengl modes was to putting the native binaries on the java.libary.path:-
jruby -Djava.library.path="/home/tux/lib/linux64" trefoil.rb
I needed to change the build to include the lwjgl jars and app.rb to accommodate the changes to processing but also unlike vanilla processing the sketch was also modified, replacing the applet convention of size(width, height, renderer) in setup with 3 methods (not required to be called in setup):-
# Old
  def setup
    size(1024, 768, P3D)
  def sketch_width

  def sketch_height

  def sketch_renderer

Here is a working 'bare' JAVA2D sketch (run using k9 run keyboard.rb) which was tested with jruby-complete-
def setup
  @num_chars = 26
  @key_scale = 200.0 / @num_chars - 1.0
  @rect_width = width / 4
  background 0

def draw
  return unless key_pressed? && ('A'..'z').include?(key)
  key_index = key.ord - (key <= 'Z' ? 'A'.ord : 'a'.ord)
  fill millis % 255
  begin_rect = map1d(key_index, (0..25), (0..width - @rect_width))
  rect begin_rect, 0, @rect_width, height

def sketch_width; 640; end

def sketch_height; 360; end

def sketch_renderer; JAVA2D; end

Rubocop will complain of single line definition, but here I think it makes sense! The default renderer is currently JAVA2D, but it looks like Ben is having some success with JavaFX so that might change v. soon. It should be possible to use the java Class loader to set the java.library.path as we do in load_library, but this will probably require 'k9 run sketch', however there is work to be done to even run anything other than Java2D with k9. So presently I think I will concentrate on jruby- work.....
Allowing for Ben / Andrés to progress processing-3.0, before I waste any more time.

Warning this has all changed in favour of settings method, and defining renderer along with size as single line entry ie like processing-2.0 but in settings, not setup... furthermore jruby class loader reverted to original and the design of JRubyArt mirrored ruby-processing

No comments:

Post a Comment


About Me

My photo
I have developed JRubyArt and propane new versions of ruby-processing for JRuby- and processing-3.2.2