Skip to content

Commit 854022f

Browse files
author
monkstone
committed
examples video and sound libraries
1 parent 9799bb7 commit 854022f

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

data_path/landscape.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class Landscape < Propane::App
1111
# Processing port by Raphaël de Courville.
1212
#
1313
attr_reader :landscape
14-
java_alias :background_int, :background, [Java::int]
14+
java_alias :background_int, :background, [Java::int]
15+
TITLE_FORMAT = 'frame: %d - fps: %0.2f'.freeze
1516

1617
def settings
1718
size(640, 360, P2D)
@@ -21,7 +22,7 @@ def setup
2122
sketch_title 'Landscape'
2223
no_stroke
2324
# The code of this shader shows how to integrate shaders from shadertoy
24-
# into Processing with minimal changes.
25+
# into Processing/JRubyArt/propane with minimal changes.
2526
@landscape = load_shader(data_path('landscape.glsl'))
2627
landscape.set('resolution', width.to_f, height.to_f)
2728
end
@@ -31,7 +32,7 @@ def draw
3132
landscape.set('time', (millis/1000.0).to_f)
3233
shader(landscape)
3334
rect(0, 0, width, height)
34-
frame.set_title("frame: #{frame_count} - fps: #{format('%0.2f', frame_rate)}")
35+
sketch_title(format(TITLE_FORMAT, frame_count, frame_rate))
3536
end
3637
end
3738

regular/pink_noise.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This is a simple pink noise generator. It can be started with .play(amp).
2+
# In this example it is started and stopped by clicking into the renderer window.
3+
require 'propane'
4+
5+
class PinkNoiseApp < Propane::App
6+
load_library :sound
7+
include_package 'processing.sound'
8+
9+
attr_reader :amp, :noise
10+
11+
def settings
12+
size(640, 360)
13+
end
14+
15+
def setup
16+
sketch_title 'Pink Noise'
17+
background(255)
18+
@amp = 0.0
19+
# Create the noise generator
20+
@noise = PinkNoise.new(self)
21+
noise.play(amp)
22+
end
23+
24+
def draw
25+
# Map mouseX from 0.0 to 1.0 for amplitude
26+
noise.amp(map1d(mouse_x, (0..width), (0.0..1.0)))
27+
# Map mouseY from -1.0 to 1.0 for left to right
28+
noise.pan(map1d(mouse_y, (0..height), (-1.0..1.0)))
29+
end
30+
end
31+
32+
PinkNoiseApp.new

regular/test_capture.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require 'propane'
2+
3+
class TestCapture < Propane::App
4+
load_library :video, :video_event
5+
include_package 'processing.video'
6+
attr_reader :cam
7+
8+
def setup
9+
sketch_title 'Test Capture'
10+
cameras = Capture.list
11+
fail 'There are no cameras available for capture.' if (cameras.length == 0)
12+
p 'Matching cameras available:'
13+
size_pattern = Regexp.new(format('%dx%d', width, height))
14+
select = cameras.grep size_pattern # filter available cameras
15+
select.uniq.map { |cam| p cam.strip }
16+
fail 'There are no matching cameras.' if (select.length == 0)
17+
start_capture(select[0])
18+
end
19+
20+
def start_capture(cam_string)
21+
# The camera can be initialized directly using an
22+
# element from the array returned by list:
23+
@cam = Capture.new(self, cam_string)
24+
p format('Using camera %s', cam_string)
25+
cam.start
26+
end
27+
28+
def draw
29+
image(cam, 0, 0, width, height)
30+
# The following does the same, and is faster when just drawing the image
31+
# without any additional resizing, transformations, or tint.
32+
# set(0, 0, cam)
33+
end
34+
35+
def captureEvent(c)
36+
c.read
37+
end
38+
39+
def settings
40+
size 960, 544, P2D
41+
end
42+
end
43+
44+
TestCapture.new
45+

0 commit comments

Comments
 (0)