Figure 25—You can find good online editors for pixel graphics.
When ImageMagick is available on your system, you can install the rmagick
library using the following command:
maik> gem install rmagick
Now you can use rmagick in your Ruby programs. We’ll use it to convert a
graphics file into a C++ file:
Video/img2cpp.rb
require 'RMagick'
Line 1
include Magick
-
-
image = Image::read(ARGV[0]).first
-
5
puts '#include "thermometer.h"'
-
puts 'PROGMEM const unsigned char thermometer[] = {'
-
puts " #{image.columns}, #{image.rows},"
-
-
(0..image.rows).each do |y|
10
print ' B'
-
(0..image.columns).each do |x|
-
pixel = image.pixel_color(x, y)
-
print pixel.red == 0 ? '0' : '1'
-
print ', B' if (x + 1) % 8 == 0
15
Chapter 8. Generating Video Signals with an Arduino • 142
report erratum • discuss
www.it-ebooks.info