Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of git://github.com/martinstannard/ruby-processing
- Loading branch information
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
samples/learning_processing/chapter_15/15_2d_image_mapped_to_3d.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
28
samples/learning_processing/chapter_16/01_display_video.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
26 changes: 26 additions & 0 deletions
26
samples/learning_processing/chapter_16/02_manipulate_video_image.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |