1717def setup
1818 sketch_title 'Mirror'
1919 frameRate ( 30 )
20- @cols = width / CELL_SIZE
21- @rows = height / CELL_SIZE
2220 color_mode ( RGB , 255 , 255 , 255 , 100 )
23- @video = Java :: ProcessingVideo :: Capture . new ( self , width , height )
21+ @video = Capture . new ( self , width , height )
2422 # Start capturing the images from the camera
2523 video . start
2624 background ( 0 )
@@ -29,14 +27,11 @@ def setup
2927def draw
3028 video . load_pixels
3129 # Begin loop for columns
32- cols . times do |i |
30+ ( 0 ... width ) . step ( CELL_SIZE ) do |i |
3331 # 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 |
3833 # Reversing x to mirror the image
39- loc = ( video . width - x - 1 ) + y * video . width
34+ loc = ( width - i - 1 ) + j * width
4035 r = red ( video . pixels [ loc ] )
4136 g = green ( video . pixels [ loc ] )
4237 b = blue ( video . pixels [ loc ] )
@@ -45,7 +40,7 @@ def draw
4540 # Code for drawing a single rect
4641 # Using translate in order for rotation to work properly
4742 push_matrix
48- translate ( x + CELL_SIZE / 2 , y + CELL_SIZE / 2 )
43+ translate ( i + CELL_SIZE / 2 , j + CELL_SIZE / 2 )
4944 # Rotation formula based on brightness
5045 rotate ( ( 2 * PI * brightness ( c ) / 255.0 ) )
5146 rect_mode ( CENTER )
0 commit comments