17
17
def setup
18
18
sketch_title 'Mirror'
19
19
frameRate ( 30 )
20
- @cols = width / CELL_SIZE
21
- @rows = height / CELL_SIZE
22
20
color_mode ( RGB , 255 , 255 , 255 , 100 )
23
- @video = Java :: ProcessingVideo :: Capture . new ( self , width , height )
21
+ @video = Capture . new ( self , width , height )
24
22
# Start capturing the images from the camera
25
23
video . start
26
24
background ( 0 )
@@ -29,14 +27,11 @@ def setup
29
27
def draw
30
28
video . load_pixels
31
29
# Begin loop for columns
32
- cols . times do |i |
30
+ ( 0 ... width ) . step ( CELL_SIZE ) do |i |
33
31
# Begin loop for rows
34
- rows . times do |j |
35
- # Where are we, pixel-wise?
36
- x = i * CELL_SIZE
37
- y = j * CELL_SIZE
32
+ ( 0 ...height ) . step ( CELL_SIZE ) do |j |
38
33
# Reversing x to mirror the image
39
- loc = ( video . width - x - 1 ) + y * video . width
34
+ loc = ( width - i - 1 ) + j * width
40
35
r = red ( video . pixels [ loc ] )
41
36
g = green ( video . pixels [ loc ] )
42
37
b = blue ( video . pixels [ loc ] )
@@ -45,7 +40,7 @@ def draw
45
40
# Code for drawing a single rect
46
41
# Using translate in order for rotation to work properly
47
42
push_matrix
48
- translate ( x + CELL_SIZE / 2 , y + CELL_SIZE / 2 )
43
+ translate ( i + CELL_SIZE / 2 , j + CELL_SIZE / 2 )
49
44
# Rotation formula based on brightness
50
45
rotate ( ( 2 * PI * brightness ( c ) / 255.0 ) )
51
46
rect_mode ( CENTER )
0 commit comments