Skip to content

Commit af7e7f2

Browse files
committed
fix mirror2
1 parent e6505d7 commit af7e7f2

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

library/video/capture/background_subtraction.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ def captureEvent(c)
7575

7676
def key_pressed
7777
video.load_pixels
78-
@background_pixels = video.pixels.clone
78+
@background_pixels = video.pixels.copy
7979
end
8080

8181
def settings
82-
size(960, 720, P2D)
82+
size(480, 360, P2D)
8383
end
8484
end
8585

library/video/capture/mirror2.rb

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,48 @@
77
# on brightness.
88
class Mirror2 < Processing::App
99
load_library :video
10-
include_package 'processing.video'
11-
10+
java_import 'processing.video.Capture'
11+
attr_reader :video, :cols, :rows
12+
# Size of each cell in the grid
1213
CELL_SIZE = 15
1314

14-
attr_reader :video
15-
1615
def setup
17-
sketch_title 'Mirror2'
18-
# Set up columns and rows
19-
color_mode(RGB, 255, 255, 255, 100)
20-
rect_mode(CENTER)
21-
# This the default video input, see the GettingStartedCapture
22-
# example if it creates an error
16+
sketch_title 'mirror'
17+
frame_rate(30)
18+
@cols = width / CELL_SIZE
19+
@rows = height / CELL_SIZE
20+
colorMode(RGB, 255, 255, 255, 100)
21+
# Try test_capture to find name of your Camera
2322
@video = Capture.new(self, width, height, "UVC Camera (046d:0825)")
2423
# Start capturing the images from the camera
2524
video.start
26-
background(0)
2725
end
2826

2927
def draw
30-
return unless video.available
28+
return unless video.available # ruby guard clause
3129

30+
background(0, 0, 255)
3231
video.read
3332
video.load_pixels
34-
background(0, 0, 255)
35-
# Begin loop for columns
36-
grid(width, height, CELL_SIZE, CELL_SIZE) do |x, y|
37-
loc = (width - x - 1) + y * width
38-
# Each rect is colored white with a size determined by brightness
39-
c = video.pixels[loc]
40-
sz = (brightness(c) / 255.0) * CELL_SIZE
33+
grid(cols, rows) do |i, j|
34+
x = i * CELL_SIZE
35+
y = j * CELL_SIZE
36+
loc = (width - x -1 + y * width)# Reversing x to mirror the image
37+
col = video.pixels[loc]
38+
# Code for drawing a single rect
39+
# Using translate in order for rotation to work properly
40+
# rectangle size is based on brightness
41+
sz = g.brightness(col) / 255 * CELL_SIZE
42+
rect_mode(CENTER)
4143
fill(255)
4244
no_stroke
45+
# Rects are larger than the cell for some overlap
4346
rect(x + CELL_SIZE / 2, y + CELL_SIZE / 2, sz, sz)
4447
end
4548
end
4649

4750
def settings
48-
size(480, 360, P2D)
51+
size(480, 360)
4952
end
5053
end
5154

0 commit comments

Comments
 (0)