jashkenas / ruby-processing

Code as Art, Art as Code. Processing and Ruby are meant for each other.
http://github.com/jashkenas/ruby-processing/wikis
Other
1.28k stars 94 forks source link

capture_event does not seem to fire for Capture class instance #32

Closed jurisgalang closed 13 years ago

jurisgalang commented 13 years ago

Here's a sample Sketch to recreate the issue:

require 'ruby-processing'

class Sketch < Processing::App
  load_library :video
  import "processing.video.Capture"

  def setup
    size 640, 480
    @video = Capture.new self, width, height, 32
  end

  def capture_event video
    @video.read
  end

  def draw
    image @video, 0, 0
  end
end

A workaround is to not rely on capture_event method, and just check the Camera#available? return value:

def draw
  @video.read if @video.available?
  image @video, 0, 0
end
moumar commented 13 years ago

unfortunately java reflection on jruby objects (which is used by video library and others) doesn't works. The only workaround is to use the method you described.

jurisgalang commented 13 years ago

Yeah, kinda figured that out sometime ago. :-)