alternative ruby methods
You can use most processing methods in propane, but where possible you should prefer these ruby alternatives (you should also prefer Vec2D and Vec3D to PVector).
Here is a list of ruby alternatives to some ‘processing’ convenience methods; which with the exception of color
, map1d
, p5map
, degrees
and radians
are just regular ruby methods.
function | processing | propane |
---|---|---|
camera | camera(args) |
kamera(hash_args) |
color string | color(#cc6600) |
color('#cc6600') |
date/time | t = Time.now |
|
day |
t.day |
|
hour |
t.hour |
|
minute |
t.minute |
|
second |
t.second |
|
year |
t.year |
|
custom math | map(x, b0, eo, b1, e1) |
map1d(x, (b0..e0), (b1..e1)) |
map(x, b0, eo, b1, e1) |
p5map(x, b0, e0, b1, e1) |
|
constrain(x, min, max) |
x.clamp(min,max) |
|
max(array) |
array.max |
|
min(array) |
array.min |
|
conversion | degrees(theta) |
theta.degrees |
conversion | radians(theta) |
theta.radians |
conversion | hex(string) |
string.hex |
conversion | unhex(string) |
string.to_i(base=16) |
conversion | binary(c) |
c.to_s(2) |
conversion | unbinary(string) |
string.to_i(base=2) |
math | abs(x) |
x.abs |
math | round(x) |
x.round |
math | ceil(x) |
x.ceil |
math | random(x) |
rand(x) |
math | random(a, b) |
rand(a..b) |
math power | pow(a, b) |
a**b |
square | sq(x) |
x * x |
println(x) |
puts x |
|
format | trim(string) |
string.strip |
format | nf(float_value, 0, 2) |
format('%.2f', float_value) |
format | nf(num, digit) |
num.to_s.rjust(digit, '0') |
format | nf(nf(num, left, right) |
see below |
num.to_s.rjust(left, '0').ljust(left + right, '0')
For examples of using time in sketches see learning JRubyArt blog, timestamp and this clock sketch.
For example of kamera
usage see kamera. To use selectInput
see link to File Chooser
in page header. We actually use the ruby Enumerable methods max
and min
methods to make max(*array)
and min(*methods)
available in propane, so you could use the processing form providing you splat the array, but it is simpler to use the ruby method directly further you have the option with ruby of changing the [comparator via a block][comparator].
NB: if you have any trouble with save
or save_frame
then use the option of providing an absolute path. You can easily do this using the data_path
wrapper that does it for you see data_path method.
Since propane-3.9.0 processing noise has been replaced by a wrapper around SimplexNoise, the FastNoise module is included as a default generator. To use the smooth alternative SmoothNoise module call it directly:-
SmoothNoise.noise(...) # classic noise
SmoothNoise.tnoise(...) # more suitable for terrain etc