Skip to content

Using the Processing API

jashkenas edited this page Sep 12, 2010 · 42 revisions

All of the Processing methods, as explained in the Processing Language API, are available as instance methods on your Processing::App. (frame_rate, ellipse, and the 158 others.) This makes it easy as pie to use them within your sketch.

# Triangles gone wild

def setup
  color_mode RGB, 1.0
  frame_rate 30
  fill 0.8, 0.6
  smooth
end

def draw
  triangle(rand(width), rand(height), rand(width), rand(height), rand(width), rand(height))
end

Many methods that you might expect to find under their Processing names will be available by more Rubyish monikers. “keyPressed” becomes “key_pressed?”, for instance. And some things are better done with regular Ruby than with Processing; instead of using load_strings("file.txt") to read in a file, consider File.readlines("file.txt").

Because of this method madness, Processing::Apps have a convenience method for searching through them. $app.find_method("ellipse") will return a list of the method names that may match what you’re looking for: “ellipse”, “ellipseMode”, and “ellipse_mode”.

Clone this wiki locally