Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/martinstannard/ruby-processing
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Jan 14, 2009
2 parents 4f5e5e3 + 648bdc8 commit eaa7016
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
44 changes: 44 additions & 0 deletions samples/learning_processing/chapter_15/15_2d_image_mapped_to_3d.rb
@@ -0,0 +1,44 @@
require 'ruby-processing'

class TwoDMappedTo3dSketch < Processing::App

def setup
@cellsize = 2
@img = load_image 'sunflower.jpg' # Load the image
@cols = width / @cellsize # Calculate number of columns
@rows = height / @cellsize # Calculate number of rows
render_mode P3D
end

def draw
background 255
@img.load_pixels
# Begin loop for columns
@cols.times do |i|
# Begin loop for rows
@rows.times do |j|
x = i * @cellsize + @cellsize / 2 # x position
y = j * @cellsize + @cellsize / 2 # y position
loc = x + y * width # Pixel array location
c = @img.pixels[loc] # Grab the color

# Calculate a z position as a function of mouseX and pixel brightness
z = (mouseX/width.to_f) * brightness(@img.pixels[loc]) - 100.0

# Translate to the location, set fill and stroke, and draw the rect
push_matrix
translate x, y, z
fill c
no_stroke
rect_mode CENTER
rect 0, 0, @cellsize, @cellsize
pop_matrix
end
end
end

end

TwoDMappedTo3dSketch.new :title => "2d Mapped To 3d", :width => 200, :height => 200


28 changes: 28 additions & 0 deletions samples/learning_processing/chapter_16/01_display_video.rb
@@ -0,0 +1,28 @@
require 'ruby-processing'

class CaptureVideoSketch < Processing::App

# Step 1. Import the video library
load_java_library "video"
# We need the video classes to be included here.
include_package "processing.video"

def setup
# Step 2. Declare a Capture object
@video = Capture.new $app, width, height, 30
end

def draw
# Check to see if a new frame is available
if @video.available
# If so, Step 4. Read the image from the camera.
@video.read
end

# Step 5. Display the video image.
image @video, 0, 0
end

end

CaptureVideoSketch.new :title => "Capture Video", :width => 320, :height => 240
@@ -0,0 +1,26 @@
require 'ruby-processing'

class ManipulateVideoImageSketch < Processing::App

load_java_library "video"
include_package "processing.video"

def setup
@video = Capture.new $app, width, height, 30
end

def draw
if @video.available
@video.read
end

# Tinting using mouse location
tint mouse_x, mouse_y, 255

# A video image can also be tinted and resized just as with a PImage.
image @video, 0, 0, mouse_x, mouse_y
end

end

ManipulateVideoImageSketch.new :title => "Manipulate Video Image", :width => 320, :height => 240

0 comments on commit eaa7016

Please sign in to comment.