Processing provides a tidy API, with a bunch of handy methods you can call from Ruby-Processing. Here's a smattering:
alpha, arc, background, blend, blue, ellipse, frame_rate, hue, lerp, load_image, load_pixels, mouse_pressed, noise, rect, saturation, shape, smooth, text_align, translate, triangle...
MacOSX users please try out this new method
Ideally you should install jruby, at the very least you will have at least ruby-1.9.3 installed. You should download and install vanilla processing-2.1.2 prior to installing this version of ruby-processing. You must also set the
PROCESSING_ROOT in the .rp5rc yaml configuration file, the easiest way to do this is by running the SetProcessingRoot.pde sketch in the processing ide.
Then install ruby-processing (from rubygems-org) in the usual way
gem install ruby-processing some systems eg Ubuntu may require
To install jruby-complete use our built in tool (relies on
wget to download jruby-complete-1.7.12)
If you haven't got
wget just download jruby-complete-1.7.12 to the vendors folder (then run above tool)
The vendored jruby-complete-1.7.12 is only required for application export, and running certain sketches (eg shader sketches see wiki).
rp5 run my_sketch.rb
or if not using system jruby
rp5 --nojruby run my_sketch.rb
where a simple
my_sketch.rb could look like this
def setup size 400, 400 fill 255 end def draw background 0 ellipse mouse_x, mouse_y, 100, 100 end
or a simple 3D sketch
def setup size 640, 360, P3D @xmag = 0 @ymag = 0 @new_xmag = 0 @new_ymag = 0 fill 200, 50, 50 end def draw background 100 push_matrix translate width/2, height/2, -30 @new_xmag = mouse_x.to_f / width * TWO_PI @new_ymag = mouse_y.to_f / height * TWO_PI diff = @xmag - @new_xmag @xmag -= diff / 4 if diff.abs > 0.01 diff = @ymag - @new_ymag @ymag -= diff / 4 if diff.abs > 0.01 rotate_x(-@ymag) rotate_y(-@xmag) box 150, 150, 150 pop_matrix end
This library has been tested with the following ruby implementations
- Ruby 1.9.3
- Ruby 2.0.0
- Ruby 2.1.0
- JRuby preferred (required to use rubygems in sketches)
New capabilities since processing-2.0 include ability to use OPENGL VBO (PShape) and GLSL shaders (PShader), to keep abreast of latest shader developments for processing check out the codeanticode blog. Some worked examples using new feature are included in the samples. The update to the latest jruby is also significant as the default is to run with ruby-1.9 support (or even use ruby-2.0 syntax with
compat.version=2.0 in your
.jrubyrc config), and there have been many performance improvements. Some performance improvements will not be available on the Mac as they require at least java-7+, and there is even more to come with java-8+ (adventurous Mac users can read more about Oracle java here ). More than 330 worked examples are included in the Samples, many of which are rubified version of the examples included with vanilla processing, and or the contributed libraries, additions are welcome. In my experience ruby-processing works even better with the recently released jdk-8 (try
-XX:+TieredCompilation option in java_args.txt). But please note you will not be able to use jdk-8 with vanilla-processing, at least for the forseeable future.