We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpProcessing Implementations › Questions regarding ruby-processing
Page Index Toggle Pages: 1
Questions regarding ruby-processing (Read 2735 times)
Questions regarding ruby-processing
Jan 22nd, 2009, 7:34am
 
I'm fairly fluent in Ruby and have been recently looking for a cross-platform graphical environment for Ruby which is how I found out about ruby-processing. I downloaded the samples, got them running under Ubuntu and it looks very nice indeed.

However, I'm having a bit of a hard time understanding how Ruby, JRuby, Java and Processing all related to each other when I run one of the samples.  For instance, as I didn't install JRuby on my Ubuntu system, does this mean that ruby-processing is using the native Ruby interpreter on my system?  If so, how is Ruby calling the Java classes that compress Processing?  I'm assuming the Processing API is essentially implemented in Java, but I'm not sure of this.

I checked the ruby-processing Wiki, but I didn't see much to describe what's happening behind the scenes.  Could someone provide a link to some on-line resources that describe how Ruby, JRuby, Java and Processing all related to each other?  Or, perhaps provide a brief description here.

I obviously have a bit of learning to do about JRuby and Processing, but I thought by posting here I could accelerate some of my learning.

Thanks,

Mike Thompson
Re: Questions regarding ruby-processing
Reply #1 - Jan 22nd, 2009, 9:03am
 
I guess I can answer one of my own questions.  It seems that ruby-processing ships with its own copy of the JRuby jar files.  It is indeed JRuby running when one invokes the rb5 command.
Re: Questions regarding ruby-processing
Reply #2 - Jan 22nd, 2009, 7:37pm
 
Hi Mike.

I'll try to add a page sometime soon on the wiki about Ruby-Processing internals, and I'll update this post when that happens, but for now here's a quick overview:

When you run the rp5 command, it starts out in regular ruby, ensuring that your sketch exists, figuring out the command you want to run and generating any applets or applications if that's what you asked for...

If rp5 determines that you want to run a sketch (either run, watch, or live), it replaces itself with a Java process that loads JRuby, and JRuby proceeds to load the Ruby-Processing codebase and start the sketch.

Things get interesting inside of JRuby, though, because you're running a processing sketch inside of a class hierarchy that looks like this:

processing.core.PApplet  (Java Space)
Processing::App                 (JRuby Space)
YourSketch                          (JRuby Space)

When you call methods inside of your sketch, JRuby may be calling methods in either JRuby or Java space, depending on whether the method is defined in the Processing::App or the processing.core.PApplet. For most methods defined in the Processing API, that means calling into Java, with JRuby taking care of converting all the arguments. However, some useful methods (like load_library and render_mode) are defined in Ruby.

Hope that clears things up a bit. It's really just a thin skin between Processing and JRuby, and relies heavily on the fact that JRuby classes are able to subclass Java-defined classes.

-- omygawshkenas
Re: Questions regarding ruby-processing
Reply #3 - Jan 23rd, 2009, 9:50am
 
Thank you for the detailed explanation.  It sounds like I need to look further into how JRuby relates to Java classes before I'm ready to look deeper at the Ruby-Processing internals.

Mike
Re: Questions regarding ruby-processing
Reply #4 - Jan 24th, 2009, 5:01pm
 
I've posted a page that talks about some of the details on the wiki:

http://wiki.github.com/jashkenas/ruby-processing/ruby-processing-internals-and-jruby-tricks

Hope it's useful.
Re: Questions regarding ruby-processing
Reply #5 - Feb 24th, 2009, 12:13pm
 
I've only just tried out ruby-processing, but I think I may have stumbled on a handy wrinkle. When I tried to set the background of my sketch as an image I kept getting the complaint that the image size must match sketch size (even when same image and command worked on vanilla-processing as the image was right size).
What did work for me was to resize the the image in the setup to width, height.
Am I right? Or what was I doing wrong?

http://myweb.tiscali.co.uk/monkstone/ruby-saucer/animated_image.html is link to my code
Re: Questions regarding ruby-processing
Reply #6 - Feb 25th, 2009, 2:19am
 
The vanilla Processing IDE might be doing some behind-the-scenes resizing that I'm not aware of, but your image isn't quite the right size. You can print out the dimensions of the image both before and after you resize it, like so:

@starfield  = load_image "space.jpg"  
puts "before width: #{starfield.width}, height: #{starfield.height}"
starfield.resize width, height
puts "after width: #{starfield.width}, height: #{starfield.height}"

and you'll get this output:

before width: 819, height: 501
after width: 800, height: 500
Re: Questions regarding ruby-processing
Reply #7 - Feb 25th, 2009, 7:47am
 
Thanks for the swift reply I did try using actual image size (I had used feh to determine the actual image size), and it still did not work (sorry I had not anticipated that you would find my actual image, once I did the resizing I thought I would round down the numbers, as they are bit odd).
Page Index Toggle Pages: 1