# # Mirror # by Daniel Shiffman. # # Each pixel from the video source is drawn as a rectangle with rotation # based on brightness. load_library :video include_package 'processing.video' # Size of each cell in the grid CELL_SIZE = 20 # Variable for capture device attr_reader :cols, :rows, :video def setup size(640, 480) frameRate(30) @cols = width / CELL_SIZE @rows = height / CELL_SIZE color_mode(RGB, 255, 255, 255, 100) @video = Capture.new(self, width, height) # Start capturing the images from the camera video.start background(0) end def draw return unless video.available video.read video.load_pixels # Begin loop for columns cols.times do |i| # Begin loop for rows rows.times do |j| # Where are we, pixel-wise? x = i * CELL_SIZE y = j * CELL_SIZE # Reversing x to mirror the image loc = (video.width - x - 1) + y * video.width r = red(video.pixels[loc]) g = green(video.pixels[loc]) b = blue(video.pixels[loc]) # Make a new color with an alpha component c = color(r, g, b, 75) # Code for drawing a single rect # Using translate in order for rotation to work properly push_matrix translate(x + CELL_SIZE / 2, y + CELL_SIZE / 2) # Rotation formula based on brightness rotate((2 * PI * brightness(c) / 255.0)) rect_mode(CENTER) fill(c) no_stroke # Rects are larger than the cell for some overlap rect(0, 0, CELL_SIZE + 6, CELL_SIZE + 6) pop_matrix end end end
Thursday, 22 January 2015
Mirror, a Dan Shiffman video capture sketch
Posted by monkstone at 15:35
- Installing netbeans ruby-plugin and jruby_art gem
- JRubyArt vs ruby-processing
- Netbeans, the perfect ide for jruby_art
- Cranky keyboard (unless you are a northern Europea...
- Another sound library example translated to ruby-p...
- Testing the new processing sound library in ruby-p...
- Mirror, a Dan Shiffman video capture sketch
- Experimenting with refinements
- Configuring ruby processing
- A Golan Levin video capture sketch translate to ru...
- A simplified ASCII video capture sketch in ruby pr...
- A Ben Fry video capture sketch in ruby-processing
- Video capture with ruby-processing
- ▼ January (13)
- ► 2014 (79)
- ► 2013 (94)
- ► 2010 (73)