-
Notifications
You must be signed in to change notification settings - Fork 9
From processing 3.0 to JRubyArt
Here are some the main differences moving from vanilla processing to ruby-processing:-
-
You should put size, smooth, full_screen in the settings method, not in setup
-
You do not declare types in ruby
vec = PVector.new
instead 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 cf. java) see more
-
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 theProcessing::Proxy
mixin to somewhat mimic this behaviour see app.rb. An alternative to consider is to use delegator methods usingextend Forwardable
, requiresrequire 'forwardable'
see example. In general you should try and code in regular ruby (in JRubyArt), only using processing shortcuts / methods when you need to (ie when ruby alternatives don't exist, many processing short cuts just aren't needed in ruby, and many are not even available in JRubyArt). From 3. above you should use:-
-
a**b
forpow(a, b)
pow is not available in JRubyArt -
theta.degrees
fordegrees(theta)
-
theta.radians
forradians(theta)
-
x.abs
forabs(x)
-
x.ceil
forceil(x)
-
x.round
forround(x)
-
str.strip
fortrim(str)
-
str.hex
forhex(str)
-
string.to_i(base=16)
forunhex(str)
Other ruby methods to prefer:-
-
rand(x)
torandom(x)
-
rand(lo..hi)
torandom(lo, hi)
-
puts val
(or even justp val
) toprintln(val)
-
p5map(value, start1, stop1, start2, stop2)
replacesmap(x, ...)
-
map1d(val, (range1), (range2))
is a more ruby like alternative (fewer args) -
(lo..hi).clip(amt)
toconstrain(amt, lo, hi)
it is how it is implemented
The processing map(value, start1, stop1, start2, stop2)
method is not implemented in JRubyArt, but p5map
is a direct replacement, but for a more ruby like alternative see map1d
see reference.
The place to set pixel_density
is in settings (after size would be a good place). So if you've got a retina display add pixel_density(2)
in the settings method.