1
1
#!/usr/bin/env jruby -w
2
+ # frozen_string_literal: true
3
+
2
4
require 'picrate'
3
5
# Mirror 2
4
6
# by Daniel Shiffman.
8
10
class Mirror2 < Processing ::App
9
11
load_library :video
10
12
java_import 'processing.video.Capture'
11
- attr_reader :video , :cols , :rows
13
+ attr_reader :video
12
14
# Size of each cell in the grid
13
15
CELL_SIZE = 15
14
16
15
17
def setup
16
18
sketch_title 'mirror'
17
- frame_rate ( 30 )
18
- @cols = width / CELL_SIZE
19
- @rows = height / CELL_SIZE
20
19
colorMode ( RGB , 255 , 255 , 255 , 100 )
21
- # Try test_capture to find name of your Camera
22
- @video = Capture . new ( self , width , height , "UVC Camera (046d:0825)" )
23
- # Start capturing the images from the camera
20
+ # Try test_capture to find the name of your Camera
21
+ @video = Capture . new ( self , width , height , 'UVC Camera (046d:0825)' )
24
22
video . start
25
23
end
26
24
@@ -30,25 +28,18 @@ def draw
30
28
background ( 0 , 0 , 255 )
31
29
video . read
32
30
video . load_pixels
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
31
+ grid ( width , height , CELL_SIZE , CELL_SIZE ) do |x , y |
32
+ loc = ( width - x - 1 + y * width ) # Reversing x to mirror the image
33
+ sz = brightness ( video . pixels [ loc ] ) / 255 * CELL_SIZE
42
34
rect_mode ( CENTER )
43
35
fill ( 255 )
44
36
no_stroke
45
- # Rects are larger than the cell for some overlap
46
- rect ( x + CELL_SIZE / 2 , y + CELL_SIZE / 2 , sz , sz )
37
+ rect ( x + CELL_SIZE / 2.0 , y + CELL_SIZE / 2.0 , sz , sz )
47
38
end
48
39
end
49
40
50
41
def settings
51
- size ( 480 , 360 )
42
+ size ( 960 , 544 )
52
43
end
53
44
end
54
45
0 commit comments