- 
                Notifications
    You must be signed in to change notification settings 
- Fork 89
From java processing to ruby processing
Here are some the main differences moving from vanilla processing to ruby-processing:-
- 
You do not declare types in ruby vec = PVector.newinstead ofPVector vec = new PVector()for example, however in this case you should prefer to use Vec2D and Vec3D, which are ruby-processing alternatives to PVector (but with methods that are much more ruby-like, and have extended functionality).
- 
There are no void methods (what's evaluated gets returned without needing an explicit return) 
- 
Everything is an object (this includes primitive types float, integer etc) 
- 
Confusing for beginners and especially pythonistas there is often more than one way to do it 
- 
Processing makes heavy use of java 'inner' classes (to make methods and values somewhat globally available) ruby-processing provides the Processing::Proxy mixin to somewhat mimic this behaviour see app.rb. An alternative to consider is to use delegator methods using extend Forwardable, requiresrequire 'forwardable'see JRubyArt example.
In general you should try and code in regular ruby (in ruby-processing), only using processing shortcuts / methods when you need to (ie when ruby alternatives don't exist, many processing shortcuts just aren't needed in ruby). From 3. above you should use:-
- 
a**btopow(a, b)
- 
theta.degreestodegrees(theta)
- 
theta.radianstoradians(theta)
- 
x.abstoabs(x)
- 
x.ceiltoceil(x)
- 
x.roundtoround(x)
- 
str.striptotrim(str)
- 
str.hextohex(str)
- 
string.to_i(base=16)tounhex(str)
Other ruby methods to prefer:-
- 
rand(x)torandom(x)
- 
rand(lo .. hi)torandom(lo, hi)
- 
puts val(or even justp val) toprintln(val)
Oddities to be aware of
The processing map(val, in_start, in_end, out_start, out_end) method has been implemented in ruby-processing, this is not to be confused with ruby map which is much used in ruby to map a function to an array.
You should prefer to use map1d(val, (range1), (range2)) where range1 could be (0..1) and range2 could be (0..255) to processing map.