Ruby-Processing
Are you on a Mac? Ten minutes from now you will be running your first Ruby-Processing animation, mesmerized by a color shifting 3D cube rotating in space. It's easy.
What is Ruby?

What is Processing?

Ok. So what's Ruby-Processing?

Install Ruby-Processing
1. *Open up Terminal*. It's a program that comes with OS X and is in your Applications > Utilities folder. The quickest way to find it is to click the magnifying glass in the upper-right corner of your screen and type in “Terminal.” When it opens you'll see a text window with a command-line prompt. (At Stewdio we prefer to use the Ocean theme in Terminal which gives you white text on a nice blue background. A little transparency is nice too. You can change these settings in Terminal's preference window.)Paste this into Terminal and hit Enter:
sudo gem install ruby-processing
Type in your admin password when Terminal asks for it. These programs aren't allowed to just install themselves, so that's why you need to enter your password. And don't worry, you won't be able to see your password as you're entering it but Terminal knows what you're typing. Wait for the download and install… should only be a minute. And that's it. Done. You have Ruby-Processing.
Load the Code
Now that you have Ruby-Processing installed (aka RP5 for short) it's time to write a program and run it. Or rather, why don't you just copy the code below and past it into a text file. I recommend TextMate (it's currently my favorite text editor) but if you can't afford it there's the free TextWrangler or you can just use OS X's built-in TextEdit. For TextMate I recommend the “Blackboard” theme. (To change visuals themes click on TextMate > Preferences and go to the Fonts & Color tab. Also, Menlo-Regular at 14pt is a respectable font choice. Note: If you use TextEdit make sure you click Format > Make Plain Text to remove text formatting (like font styles, sizes, colors, etc) before saving.class ColorCube < Processing::App
load_library :opengl
def setup size 640, 360, OPENGL frame_rate 30 @x_degree = 45 @y_degree = 0 @foreground_hue = 0 @background_hue = 180 color_mode HSB, 360 no_stroke end
def draw background @background_hue, 360, 360, 360 lights push_matrix
translate width / 2, height / 2, 0
rotate_x radians( @x_degree )
rotate_y radians( @y_degree )
fill @foreground_hue, 360, 360, 320
box 180
pop_matrix
@x_degree = ( @x_degree + 1 ).modulo 360
@y_degree = ( @y_degree + 2 ).modulo 360
@foreground_hue = ( @foreground_hue + 1 ).modulo 360
@background_hue = ( @foreground_hue + 180 ).modulo 360
end
end ColorCube.new :title => "My COLORFUL Cube!"
Let's spin some 3D cubes!
1. *Save this file to your Desktop as ColorCube.rb*. The ".rb" file extension helps you and your computer remember that this is a Ruby program.Open up Terminal. Or perhaps you still have it open from installing Ruby-Processing? No Matter. Your Terminal's command prompt is probably working out of your Home folder. But we want Terminal to work out of your Desktop folder because that's where we just saved our file. Copy and paste this command into Terminal and hit Enter:
cd ~/Desktop
Spin your cube. Again, copy and paste this command into Terminal and hit Enter:
rp5 run ColorCube.rb
And there you go. You should be looking at a color-shifting, rotating cube on a color-shifting background. Just hit Command+Q to Quit.
Conclusions
You have Ruby-Processing installed. You just ran your first “RP5″ animation. You're probably excited, but have a lot of questions. Try experimenting: How might I make the cube larger? Maybe it has to do with the number after that “box” command? What happens if I delete the line that says “lights”? Give it a shot. Don't worry about breaking things. If you've made a mistake and can't figure out how to fix it, just paste in this sample code again. No big deal.Again, I would direct you to the Processing Language API which lists all of the Processing commands. You will need to “Ruby-ize” these commands: Java likes to use camelCase for function names but Ruby prefers under_scores. If you run into difficulties see the RP5 Using the Processing API page for more info.
And one last thing. Remember that Terminal command we used to switch from your Home folder to your Desktop? Wouldn't it be nice to never have to type that again? What if your Ruby-Processing programs are in a folder within a folder within another folder somewhere else on your machine? Meet ShellHere, a free little Finder add-on to solve just such a problem. ShellHere adds a button to your Finder window that will open Terminal to whatever folder location you're currently viewing.
Ok. Good luck and happy coding.