processing API
Most of the processing methods, as explained in the Processing Language API, are available as instance methods to the Propane::App. (frame_rate, ellipse, many others). But there are exceptions see below and here, where good or better alternatives already exist in ruby. Also make sure you take a look at the many included example sketches, where ruby core and Math methods are preferred over the processing/java alternative eg rand(0.0..4)
is preferred over random(0, 4.0)
.
#!/usr/bin/env jruby -w
require 'propane'
class TrianglesGoneWild < Propane::App
def settings
size 600, 600
smooth 8
end
def setup
sketch_title 'Triangles Gone Wild'
color_mode RGB, 1.0
frame_rate 30
fill 0.8, 0.6
end
def draw
triangle(rand(width), rand(height), rand(width), rand(height), rand(width), rand(height))
end
end
TrianglesGoneWild.new
Some variables that you might expect to find under their Processing names are available by more rubyish names, keyPressed
becomes key_pressed?
and mousePressed
becomes mouse_pressed?
. The functions keyPressed
, mousePressed
become key_pressed
and mouse_pressed
ie without ?
. 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')
. For math use x.to_f
, x.radians
and x**3
for float(x)
, radians(x)
and pow(x, 3)
.
Because of this method madness, Propane::App
has a convenience method for searching through them. find_method('ellipse')
will return a list of the method names that may match what you’re looking for: ‘ellipse’, ‘ellipseMode’, and ‘ellipse_mode’. Please note this is an instance method, so from irb or pry use Propane.app.find_method 'ellipse'
on a loaded sketch. Alternatively add puts find_method 'ellipse'
at the end of your setup
method (or draw
but only with no_loop
).
Also prefer Vec2D
and Vec3D
to PVector
follow links for reference. Also you can/should use data_path
to wrap filenames (propane uses ruby to access the absolute_path of files in the sketch data folder, this avoids the file permission issues of the vanilla-processing method).