Getting Started With JRubyArt (stolen from Ben Lewis)
For other languages see wiki Español, more contributions welcome
If you love to code because it is a creative process, then you should give JRubyArt a try because it can be used to create music, art, animations, videos and much more. Also since it is based on the latest Processing you can access a vast range of libraries to make the difficult things easier.
What Is Processing?
Processing is a simple language, based on Java, that you can use to create digital graphics. It’s easy to learn, fun to use, and has an amazing online community comprised of programmers, visual artists, musicians, and interdisciplinary artists of all kinds.
Processing was built by Benjamin Fry and Casey Reas ☯, two protegés of interdisciplinary digital art guru John Maeda at the MIT Media Lab.
Since the project began in 2001, it’s been helping teach people to program in a visual art context using a simplified version of Java. It comes packaged as an IDE that can be downloaded and used to create and save digital art “sketches”.
In 2009, Jeremy Ashkenas (aka jashkenas, creator of Backbone.JS, Underscore.JS, and Coffeescript), published the original ruby-processing gem. It wraps Processing in a shim that makes it even easier to get started if you know Ruby. It has been since updated to use processing-2.2.1 by Martin Prout (final version using jruby-1.7.27 corresponding to ruby-1.9.3 syntax), NB: no more releases are expected, and ruby-processing is not compatible with processing-3.0+.
In 2015, Martin Prout (aka monkstone) published the JRubyArt gem, loosely based on the original ruby-processing, but updated to use processing-3.3.6 and jruby-188.8.131.52 (ruby-2.3 syntax)
Since Processing already comes wrapped in an easy-to-use package, you may ask: “why should I bother with JRubyArt?”
The answer: if you know how to write Ruby, you can use Processing as a visual presentation layer of a much more complex program. Games, interactive art exhibits, innovative music projects, anything you can imagine; it’s all at your fingertips.
Additionally, you don’t have to declare types, voids, or understand the differences between floats and ints to get started, as you do in pure Processing.
Although there are some drawbacks to using the Ruby version Processing (slower start up time, and sometimes performance), having Ruby’s API available to translate your ideas into sketches more than makes up for them.
Why was ruby-processing not updated to use processing-3.0+? The major changes between processing-2.2.1 and processing-3.0 are not backward compatible. Furthermore since JRubyArt was designed to use jruby-184.108.40.206 from the outset, it makes use of the more literate ruby-2.2 syntax (although the original ruby-processing will run with jruby-220.127.116.11, the examples and the ruby-processing library are all based on ruby-1.9.3 syntax).
Setting JRubyArt for the first time, can seem a bit involved (especially if you are addicted to rvm or rbenv). The JRubyArt gem relies on jruby-18.104.22.168+, processing-3.3.6, and a handful of other dependencies. Here’s how to get them all installed and working on the Mac.
Install homebrew, wget (using homebrew), java (1.8.0_131+)
In case you have issues, it has been reported to be useful to set the JAVA_HOME and to add the path to
java to your PATH
You can check to see what platforms are supported here. Download processing-3.3.6 from the official website and install it. When you’re done, make sure that the resulting app is located in your /Applications directory.
Fire up processing, and use the processing ide to install the sound and video libraries as these are no longer included in the download (but you will surely want them):-
Sketch/Import Library/Add Library/Video ide menu
It is possible to run JRubyArt without a system install of jruby. But you may not be able to use gems in your sketches without a jruby executable. Mac users it seems are wedded to rbenv or rvm, and should use what they generally use to install vanilla ruby, to install jruby-22.214.171.124. For the independently minded, there is a bitnami installer for jruby-126.96.36.199 or you may prefer a homebrew install for jruby-188.8.131.52. I haven’t tried either as a linux user.
JRubyArt needs to know where you’ve installed processing, where your processing sketchbook lives (for the video and audio libraries etc), and whether you’ve done a system/user install of jruby.
Config file is
config.yml in the
~/.jruby_art folder so it can co-exist with a ruby-processing install (~/.rp5rc), but not on the Mac.
# Example YAML configuration file for jruby_art on macosx PROCESSING_ROOT: /Applications/Processing.app/Contents/Java # important sketch_book path may be different for processing-3.0 sketchbook_path: # user defined path, to pick up video/audio libraries etc # set false if you haven't installed jruby, avoids need for --nojruby flag JRUBY: false # uses jruby-complete by default for running skethes template: bare # use class or emacs for alternative templates
Note that if you install processing using Home Brew you will need to prefix path to
PROCESSING_ROOT with your home directory:-
If you can/are using rvm or rbenv switch to using jruby-184.108.40.206+ then
gem install jruby_art
if you are brave (or sensible) and have done an independent jruby install
jruby -S gem install jruby_art # then install other gems eg toxiclibs the same way
but you might find regular MRI gem install works (also tends to be quicker)
gem install jruby_art
After installing the the gem you can download and install jruby-complete (but this is not absolutely required if you have an installed jruby since jruby_art-1.1.0). This is not included in the gem, because it would make it too big, providing you’ve got wget installed all you need to do is:-
k9 --install # downloads and installs jruby-complete and samples
To run a bunch of the samples as a demo:-
cd ~/k9_samples rake # autoruns a bunch of files as a demo cd ~/k9_samples/contributed # for example rake # autoruns files in contributed folder k9 --run jwishy.rb # run the JWishy sketch, using an installed jruby cd ~/k9_samples/processing_app/topics/shaders rake # autoruns shader sketches k9 --run monjori.rb # run single shader sketch, since jruby_art-1.0
Creating your own sketch
All we ask is that you obey the ruby filename convention (ie snakecase) and we can create a template sketch for you as follows:-
k9 --create fred_sketch 200 200 # creates a bare sketch fred_sketch.rb (see below) vim fred_sketch.rb :!k9 -r % # from vim runs the sketch
other editors are available
def setup sketch_title 'Fred Sketch' end def draw end def settings size 200, 200 # smooth # here end
k9 -c fred also works with a bare template defaults, to
size 200 200
Read more about using the processing api here