The MathTool and HelperMethods modules implement some of the processing convenience methods

buffer methods

See buffer

color method

A convenience method that returns a ‘color’ int for processing

color(*args)           # where args can be a hex string, a hexadecimal number, etc. see examples
color('#CC6600')       # hexadecimal string, can be lower-case
color(0xFFCC6600)      # hexadecimal
color(255)             # white
color(0)               # black
color(255, 0, 0)       # red
color(0, 0, 255)       # blue
color(0, 0, 255, 100)  # blue with alpha value 100

Example Usages: Creating, Blend Color

hsb_color method

A convenience method that returns a ‘color’ int for processing for hsb input, where hue, saturation and brightness are in range 0..1.0

hsb_color(hue, sat, bright) # where args are ruby float

web_to_color_array method

A convenience method that converts an array of web color strings to an array of ‘color’ int. Particularly useful when working with the Joshua Davis Processing-HYPE library.

WEB = %w(#CC6600 #CC9900 #FFFFFF).freeze
web_to_color_array(WEB)
# output = [-3381760, -3368704, -1]

see usage in a Wordcram sketch

p52ruby

A convenience method that converts an array of ‘color’ int to a ruby string that you can use in your Wordcram or Hype sketches (say from a ColorHarmony sketch)

p52ruby([-3381760, -3368704, -1])
# output = "%w(#CC6600 #CC9900 #FFFFFF)\n"

For toxiclibs we have created a new method to_ruby_string for the ColorList class that does the same thing for a collection of TColor See this toxiclibs sketch where we use color theory to generate a sketch palette.

map1d method

A replacement for processings map function, maps val (range1) to range2 using a linear transform.

map1d(val, range1, range2) # where val is an input float range1 is source and range2 is target
# simple example
map1d(10, (0..20), (0..1.0)) # returns 0.5

Example Usages: Mandelbrot, Game of Life

radians and degrees methods

A replacement for processings radians(x) and degree(x) methods in ruby everything is an object!!

x.radians # we did this by monkey patching ruby numeric
x.degrees

Note: ruby already provides x.abs, x.to_s, and x.to_f replacing abs(x), str(x), and float(x) etc

Example Usages: bezier ellipse, brick tower

Processing max and min convenience methods

We make these methods available in JRubyArt, by mocking them using ruby Enumerable max and min methods, you should prefer to use the Enumerable methods directly since they are more flexible (you can even provide a comparator block to change basis of ordering).

find_method method

A convenient way of finding a method

find_method(method) # where method is a method name or fragment
# simple example
puts find_method('map') # see output below
constrained_map
map1d
p5map