Skip to content

Using Other Processing Libraries

Martin Prout edited this page Feb 26, 2014 · 1 revision

Installing contributed processing libraries

Install regular processing, if you have not already done so ( this is highly recommended for users of external processing libraries, Mac users can even use the downloaded binary in the vendors folder, to install vanilla processing ). Since processing-2.0 it is possible to install many [Contributed][] libraries directly via the processing ide (see [Contributed][] where some [Legacy][] libraries are also listed). Other processing libraries should be manually installed following the [Legacy][] libraries instructions. However some [Legacy][] and other libraries may need updating to work with processing-2.0 (and hence ruby-processing-2.0+).

Loading processing libraries in a sketch

You can simply load_library or load_libraries to load the required libraries ( if installed as above ), will also either need to java_import, or for package access you can instead include_package to access the java classes. Sometimes it is more convenient to create a module to allow access to these packages (see an example below). Read more about calling java from ruby at the [JRuby Wiki][].

load_libraries 'simutils','toxiclibscore','colorutils'

module Toxi
  include_package "toxi.sim.grayscott"
  include_package "toxi.math"
  include_package "toxi.color"
end

Java constants in ruby-processing

Using the toxiclibs example above, we created a Toxi namespace by creating a Toxi module. Note to access the named color constants use :: not the dot separator.

@tone_map = Toxi::ToneMap.new(0,  0.33, Toxi::NamedColor::CRIMSON, Toxi::NamedColor::WHITE, 256)

Also see the many included [External Library][] examples, which should help to get you started

Initializing processing libraries

Processing libraries built according to the [Build Instructions][] need to be initialized with the instance of the processing PApplet. So for example to use PeasyCam in processing:-

PeasyCam myCam = new PeasyCam(this, 100); // this is the PApplet instance 

For ruby-processing you should replace this with self:-

@my_cam = PeasyCam.new(self, 100)

Some library builders like to do it differently so for the fisica library this becomes:-

Fisica.init(self)

Possible Issues

If you get a method/variable missing message when using JRuby-Complete ( ie using the --nojruby flag ) it might be worth trying to run the sketch using an external jruby ( default since version 2.1.2 ). This is the case for the fisica library (which has a lazily "protected" abstract class which is "invisible" when using JRuby-Complete). [Build Instructions]:https://github.com/processing/processing/wiki [Jruby Wiki]:https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby/ [Contributed]:http://processing.org/reference/libraries/ [Legacy]:http://wiki.processing.org/w/How_to_Install_a_Contributed_Library [External Library]:https://github.com/jashkenas/ruby-processing/tree/master/samples/external_library/java_processing