1
1
# This example demonstrates how to use the video library. You'll need a
2
2
# video camera hooked in to your computer.
3
3
4
- class TextMirror < Processing ::App
5
- load_library "video"
6
- import "processing.video"
7
4
8
- # Size of each cell in the grid, ratio of window size to video size
9
- VIDEOSCALE = 14
5
+ load_library : video
6
+ include_package "processing.video"
10
7
11
- # The source text used in the mosaic pattern.
12
- # A longer String might produce more interesting results.
13
- CHARS = "thetextmirror"
8
+ # Size of each cell in the grid, ratio of window size to video size
9
+ VIDEOSCALE = 14
14
10
15
- def setup
16
- size 640 , 480
17
- smooth
18
- # Set up columns and rows
19
- @cols = width / VIDEOSCALE # Number of columns and...
20
- @rows = height / VIDEOSCALE # rows in our system
21
- @video = Capture . new ( self , @cols , @rows , 15 )
11
+ # The source text used in the mosaic pattern.
12
+ # A longer String might produce more interesting results.
13
+ CHARS = "thetextmirror"
22
14
23
- # Load the font
24
- # Using a fixed-width font. In most fonts, individual characters have different widths.
25
- # In a fixed-width font, all characters have the same width.
26
- # This is useful here since we intend to display the letters one at a time spaced out evenly.
27
- # See Section 17.7 for how to display text character by character with a nonfixed width font.
28
- @f = load_font "Courier-Bold-20.vlw"
29
- end
30
-
31
- def draw
32
- background 0
33
-
34
- # Read image from the camera
35
- @video . read if @video . available?
36
- @video . load_pixels
37
-
38
- # Use a variable to count through chars in String
39
- charcount = 0
40
- # Begin loop for rows
41
- @rows . times do |j |
42
- # Begin loop for columns
43
- @cols . times do |i |
44
-
45
- # Where are we, pixel-wise?
46
- x = i * VIDEOSCALE
47
- y = j * VIDEOSCALE
48
-
49
- # Looking up the appropriate color in the pixel array
50
- c = @video . pixels [ i + j * @video . width ]
51
-
52
- # Displaying an individual character from the String instead of a rectangle
53
- text_font @f
54
- fill c
55
-
56
- # One character from the source text is displayed colored accordingly to the pixel location.
57
- # A counter variableâ charcountâ is used to walk through the source String one character at a time.
58
- text CHARS [ charcount ] . chr , x , y
59
-
60
- # Go on to the next character
61
- charcount = ( charcount + 1 ) % CHARS . length
62
- end
63
- end
64
- end
15
+ def setup
16
+ size 640 , 480
17
+ smooth
18
+ # Set up columns and rows
19
+ @cols = width / VIDEOSCALE # Number of columns and...
20
+ @rows = height / VIDEOSCALE # rows in our system
21
+ @video = Capture . new ( self , @cols , @rows , 15 )
22
+
23
+ # Load the font
24
+ # Using a fixed-width font. In most fonts, individual characters have different widths.
25
+ # In a fixed-width font, all characters have the same width.
26
+ # This is useful here since we intend to display the letters one at a time spaced out evenly.
27
+ # See Section 17.7 for how to display text character by character with a nonfixed width font.
28
+ @f = load_font "Courier-Bold-20.vlw"
29
+ end
65
30
31
+ def draw
32
+ background 0
33
+
34
+ # Read image from the camera
35
+ @video . read if @video . available?
36
+ @video . load_pixels
37
+
38
+ # Use a variable to count through chars in String
39
+ charcount = 0
40
+ # Begin loop for rows
41
+ @rows . times do |j |
42
+ # Begin loop for columns
43
+ @cols . times do |i |
44
+
45
+ # Where are we, pixel-wise?
46
+ x = i * VIDEOSCALE
47
+ y = j * VIDEOSCALE
48
+
49
+ # Looking up the appropriate color in the pixel array
50
+ c = @video . pixels [ i + j * @video . width ]
51
+
52
+ # Displaying an individual character from the String instead of a rectangle
53
+ text_font @f
54
+ fill c
55
+
56
+ # One character from the source text is displayed colored accordingly to the pixel location.
57
+ # A counter variableâ charcountâ is used to walk through the source String one character at a time.
58
+ text CHARS [ charcount ] . chr , x , y
59
+
60
+ # Go on to the next character
61
+ charcount = ( charcount + 1 ) % CHARS . length
62
+ end
63
+ end
66
64
end
67
65
68
- TextMirror . new :title => "Text Mirror"
0 commit comments