-
Notifications
You must be signed in to change notification settings - Fork 9
How to mimic "vanilla processing" inner classes
Martin Prout edited this page Apr 3, 2015
·
6 revisions
Regular processing makes much use of java "inner classes" to make PApplet methods and variables to the inner classes (with ruby-processing you can include the Processing::Proxy module to achieve a similar result.
In JRubyArt Processing::Proxy is a class not a module (and it is designed to allow the use of java reflection methods (pre
, draw
, post
etc) by inheriting classes, so basically it does not do the same thing). However you can use ruby forwardable
instead, to produce an even more elegant solution (inmho). See Node class below:-
require 'forwardable'
class Node < Physics::VerletParticle2D
extend Forwardable
def_delegators(:@app, :fill, :stroke, :stroke_weight, :ellipse)
def initialize(pos)
super(pos)
@app = $app
end
# All we're doing really is adding a display function to a VerletParticle
def display
fill(50, 200, 200, 150)
stroke(50, 200, 200)
stroke_weight(2)
ellipse(x, y, 16, 16)
end
end
To be even more kosher you could replace the global $app
via an extra initialize argument.