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

load_pixels does not appear to work for Capture class #31

Closed jurisgalang closed 11 years ago

jurisgalang commented 13 years ago

Here's a sample sketch to recreat it:

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 draw
    @video.read if @video.available? 

    @img = create_image width, height, RGB
    @video.load_pixels
    @img.load_pixels
    @video.pixels.each_with_index do |pixel, index|
      @img.pixels[index] = @video.pixels[index]
    end
    @img.update_pixels

    image(@img, 0, 0) unless @img.nil? 
  end
end

It won't display the last captured frame as expected.

jurisgalang commented 13 years ago

Here's a workaround - replace the import "processing.video.Capture" line with:

include_package "processing.video"

Not really sure why that works.

monkstone commented 11 years ago

load_library :video include_package 'processing.video'

attr_reader :img, :video

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

def draw video.read if video.available?

@img = create_image width, height, RGB @video.load_pixels img.load_pixels video.pixels.each_with_index do |pixel, index| img.pixels[index] = pixel end img.update_pixels
image(img, 0, 0) unless img.nil? end

I don't have camera attached so above is untested, should work with my beta version of ruby-processing. I'm moving towards using 'include_package' in place of import (java_import is now preferred over import) since the processing app is wrapped in a module this should work. Note also moving toward the use of 'bare sketch'. @jurisgalang might be still interested?

monkstone commented 11 years ago

@jurisgalang Have you tried the development version? Now available here (you could update your fork)

monkstone commented 11 years ago

No interest after two-months closing, jurisgalang can always re-open it.