33# by Ben Fry, translated to ruby-processing by Martin Prout.
44#
55#
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.
77# This sketch is a simple homage that re-interprets live video as ASCII text.
88# See the key_pressed function for more options, like changing the font size.
99#
1717LETTER_ORDER = LETTER_STRING . scan ( /./ )
1818def setup
1919 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
2621 @font_size = 1.5
2722 @font = load_font ( data_path ( 'UniversLTStd-Light-48.vlw' ) )
2823 # for the 256 levels of brightness, distribute the letters across
@@ -34,6 +29,15 @@ def setup
3429 @bright = Array . new ( video . width * video . height , 128 )
3530end
3631
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+
3741def capture_event ( c )
3842 c . read
3943 background 0
@@ -77,13 +81,17 @@ def draw
7781 pop_matrix
7882 end
7983 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
8587end
8688
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+
8795#
8896# Handle key presses:
8997# 'c' toggles the cheat screen that shows the original image in the corner
@@ -92,15 +100,11 @@ def draw
92100#
93101def key_pressed
94102 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
103107 else
104- p 'Controls are g to save_frame, f & F to set font size'
108+ warn MESSAGE
105109 end
106110end
0 commit comments