3
3
# by Ben Fry, translated to ruby-processing by Martin Prout.
4
4
#
5
5
#
6
- # Text characters have been used to represent images since the earliest computers.
6
+ # Text chars have been used to represent images since the earliest computers.
7
7
# This sketch is a simple homage that re-interprets live video as ASCII text.
8
8
# See the key_pressed function for more options, like changing the font size.
9
9
#
17
17
LETTER_ORDER = LETTER_STRING . scan ( /./ )
18
18
def setup
19
19
size ( 640 , 480 )
20
- # This the default video input, see the GettingStartedCapture
21
- # example if it creates an error
22
- @video = Capture . new ( self , 160 , 120 )
23
- # @cheat_screen = true
24
- # Start capturing the images from the camera
25
- video . start
20
+ init_video
26
21
@font_size = 1.5
27
22
@font = load_font ( data_path ( 'UniversLTStd-Light-48.vlw' ) )
28
23
# for the 256 levels of brightness, distribute the letters across
@@ -34,6 +29,15 @@ def setup
34
29
@bright = Array . new ( video . width * video . height , 128 )
35
30
end
36
31
32
+ def init_video
33
+ # This the default video input, see the test_capture
34
+ # example if it creates an error
35
+ @video = Capture . new ( self , 160 , 120 )
36
+ # Start capturing the images from the camera
37
+ video . start
38
+ @cheat_screen = false
39
+ end
40
+
37
41
def capture_event ( c )
38
42
c . read
39
43
background 0
@@ -77,13 +81,17 @@ def draw
77
81
pop_matrix
78
82
end
79
83
pop_matrix
80
- if cheat_screen
81
- # image(video, 0, height - video.height)
82
- # set() is faster than image() when drawing untransformed images
83
- set ( 0 , height , video )
84
- end
84
+ # image(video, 0, height - video.height)
85
+ # set() is faster than image() when drawing untransformed images
86
+ set ( 0 , height - video . height , video ) if cheat_screen
85
87
end
86
88
89
+ MESSAGE = <<-EOS
90
+ Controls are:
91
+ g to save_frame, f & F to set font size
92
+ c to toggle cheat screen display
93
+ EOS
94
+
87
95
#
88
96
# Handle key presses:
89
97
# 'c' toggles the cheat screen that shows the original image in the corner
@@ -92,15 +100,11 @@ def draw
92
100
#
93
101
def key_pressed
94
102
case key
95
- when 'g'
96
- save_frame
97
- when 'c'
98
- @cheat_screen = !cheat_screen
99
- when 'f'
100
- @font_size *= 1.1
101
- when 'F'
102
- @font_size *= 0.9
103
+ when 'g' then save_frame
104
+ when 'c' then @cheat_screen = !cheat_screen
105
+ when 'f' then @font_size *= 1.1
106
+ when 'F' then @font_size *= 0.9
103
107
else
104
- p 'Controls are g to save_frame, f & F to set font size'
108
+ warn MESSAGE
105
109
end
106
110
end
0 commit comments