processing5
Sound library
5A vanilla processing (java) library
First load the sound library (assumes it was installed using propane --install Sound)
You might just as well include_package to get namespace access to the processing.sound package.
# This is a simple pink noise generator. It can be started with .play(amp).
# In this example it is started and stopped by clicking into the renderer window.
require 'propane'
class PinkNoiseApp < Propane::App
load_library :sound
include_package 'processing.sound'
attr_reader :amp, :noise
def settings
size(640, 360)
end
def setup
sketch_title 'Pink Noise'
background(255)
@amp = 0.0
# Create the noise generator
@noise = PinkNoise.new(self)
noise.play(amp)
end
def draw
# Map mouseX from 0.0 to 1.0 for amplitude
noise.amp(map1d(mouse_x, (0..width), (0.0..1.0)))
# Map mouseY from -1.0 to 1.0 for left to right
noise.pan(map1d(mouse_y, (0..height), (-1.0..1.0)))
end
end
PinkNoiseApp.new
Listing vanilla processing contributed libraries and their urls
wget http://download.processing.org/contribs/contribs.txt
Installing contributed vanilla processing libraries
Install libraries to your ~/.propane/libraries folder. NB: this created for you when you install the glvideo, sound or video libraries. The one unfortunate / fortunate thing is that you will be responsible for updating versions manually (can be good / bad thing).
propane -i Sound
propane -i Video
propane -i glvideo
It can make sense to convert the library names and jars from camelcase to snakecase, (ie when library creators have messed up) but just be to be consistent, as example below
cd ~/.propane/libraries
wget http://staff.city.ac.uk/~jwo/giCentre/utils/gicentreUtils.zip
unzip gicentreUtils.zip # NB: British English spelling of centre
mv gicentreUtils gicenter_utils # Use snake case, and convert spelling
cd gicenter_utils/library
mv gicentreUtils.jar gicenter_utils.jar
Here is an example sketch translated to propane, main differences are how we load libraries and access package namespace in propane. Also note the use of the data_path wrapper to access sketch data folder. Another twist is the need to cast array of ruby Numbers to java float.
require 'propane'
# Sketch to demonstrate the use of the BarChart class to draw simple bar charts.
# Version 1.3, 6th February, 2016.
# Author Jo Wood, giCentre.
class BarChartSketch < Propane::App
load_library :gicenter_utils
include_package 'org.gicentre.utils.stat' # British spelling
def settings
size(800, 300)
smooth
end
def setup # a static sketch no need for draw loop
sketch_title 'Bar Chart Sketch'
title_font = load_font(data_path('Helvetica-22.vlw'))
small_font = load_font(data_path('Helvetica-12.vlw'))
text_font(small_font)
bar_chart = BarChart.new(self)
data_float = [
2_462, 2_801, 3_280, 3_983, 4_490, 4_894, 5_642, 6_322, 6_489, 6_401,
7_657, 9_649, 9_767, 12_167, 15_154, 18_200, 23_124, 28_645, 39_471
]
bar_chart.setData(data_float.to_java(:float))
data_label = %w(1830 1840 1850 1860 1870 1880 1890 1900 1910 1920 1930 1940 1950 1960 1970 1980 1990 2000 2010)
bar_chart.setBarLabels(data_label)
bar_chart.setBarColour(color(200, 80, 80, 100))
bar_chart.setBarGap(2)
bar_chart.setValueFormat('$###,###')
bar_chart.showValueAxis(true)
bar_chart.showCategoryAxis(true)
background(255)
bar_chart.draw(10, 10, width - 20, height - 20)
fill(120)
text_font(title_font)
text('Income per person, United Kingdom', 70, 30)
text_height = text_ascent # of title font
text_font(small_font)
text('Gross domestic product measured in inflation-corrected $US', 70, 30 + text_height)
end
end
BarChartSketch.new

You can even use processings built in libraries, if you put them ~/.propane/libraries folder.
#!/usr/bin/env jruby -v -W2
#
# Geometry
# by Marius Watz.
#
require 'propane'
class Complex3D < Propane::App
load_library :pdf
include_package 'processing.pdf'
attr_reader :num, :pt, :style, :dosave
def setup
sketch_title 'Complex 3D'
background(255)
@dosave = false
@num = 150
@pt = []
@style = []
# Set up arc shapes
index = 0
(0...num).each do |i|
pt << rand(TAU) # Random X axis rotation
pt << rand(TAU) # Random Y axis rotation
pt << rand(60..80) # Short to quarter-circle arcs
pt[pt.length - 1] = rand(8..27) * 10 if rand(100) > 90
pt << rand(2..50) * 5 # Radius. Space them out nicely
pt << rand(4..32) # Width of band
pt[pt.length - 1] = rand(40..60) if (rand(100) > 90) # Width of band
pt << rand(0.005..0.0334)# Speed of rotation
# get colors
prob = rand(100)
case prob
when (0..30)
style[i * 2] = color_blended(rand, 255,0,100, 255,0,0, 210)
when (30..70)
style[i * 2] = color_blended(rand, 0,153,255, 170,225,255, 210)
when (70..90)
style[i * 2] = color_blended(rand, 200,255,0, 150,255,0, 210)
else
style[i * 2] = color(255,255,255, 220)
end
case prob
when (0..50)
style[i * 2] = color_blended(rand, 200,255,0, 50,120,0, 210)
when (50..90)
style[i * 2] = color_blended(rand, 255,100,0, 255,255,0, 210)
else
style[i * 2] = color(255, 255, 255, 220)
style[i * 2 + 1] = rand(100) % 3
end
end
end