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

Wednesday, 24 June 2009

Interactive Ruby and Ruby Processing

Truly interactive coding takes a different direction when you issue the 'rp5 live' or 'rp5 live some_sketch.rb', appears to default to 'user name sketch'. Here is my default sketch. I think you need to include a draw loop in your sketch (to ensure there is a 'live thread?'). Note that this sketch of the newer type which is implicitly wrapped in an applet.

require 'ruby-processing'

class Tux < Processing::App
        def setup
                size 200, 200
        def draw

As you will see I have created an essentially blank sketch. When run live in a console you get an accompanying irb session to interact with your sketch. You can send messages to the running applet $app, as shown in picture below (NB: just click on the image to see if you can't read the text, otherwise you might need glasses, if you can identify the background image on my desktop you probably have extra-ordinary powers, clue he is an Assyrian god):

and magically the red rectangle is drawn, what fun (I cheated slightly on this image as I saved it directly from the irb environment using the following input:
$app.save_frame("tux.png") note the ruby like syntax, uses underscore rather than camel case.

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