The Interface
package processing.core; /** * This interface makes it easier/possible to use the reflection methods * void captureEvent(Capture capture); and * void movieEvent(Movie movie); from ruby-processing * @author Martin Prout */ public interface VideoInterface { void movieEvent(processing.video.Movie movie); void captureEvent(processing.video.Capture capture); }
The video_event video library script
require 'rpextras' class Processing::App include Java::ProcessingCore::VideoInterface endNow if those processing guys had only created some decent interfaces in the first place this would have been a bit easier.
Method in Use
# # Speed. # # Use the Movie.speed method to change # the playback speed. The video_event library is # required to use "movieEvent" java reflection method # load_libraries :video, :video_event include_package 'processing.video' attr_reader :mov def setup size(640, 360) background(0) @mov = Movie.new(self, "transit.mov") mov.loop end def draw image(mov, 0, 0) new_speed = map(mouse_x, 0, width, 0.1, 2) mov.speed(new_speed) fill(255) text("%.2f" % new_speed << "X", 10, 30) end # The java reflection method def movieEvent(mov) mov.read end
A capture example
load_library :video, :video_event include_package 'processing.video' attr_reader :cam, :my_shader def setup size(640, 480, P2D) cameras = Capture.list @my_shader = load_shader('edge_detect.glsl') my_shader.set('sketchSize', width.to_f, height.to_f) start_capture(width, height) end def start_capture(w, h) @cam = Capture.new(self, w, h) cam.start end def draw image(cam, 0, 0) return if mouse_pressed? filter(my_shader) end # The java reflection method def captureEvent(cam) cam.read end
Main problem is an introduction of a compile time dependency on processing video.jar, and also seems to be safer to keep camel case for reflection method, paradoxically that may improve in latest processing where the video library becomes an external library.
No comments:
Post a Comment