Skip to content

Instantly share code, notes, and snippets.

@besi
Created May 29, 2011 10:11
Show Gist options
  • Save besi/997623 to your computer and use it in GitHub Desktop.
Save besi/997623 to your computer and use it in GitHub Desktop.
require 'RMagick'
create_tally('-----')
for i in 0...6
for x in 0...2**i
binary = x.to_s(2).rjust(i,'0');
string = binary.gsub(/0/, 'n').gsub(/1/, 'y').ljust(5, '-')
create_tally(string);
end
end
def create_tally(seq)
print "Creating image '" + seq + ".png' ... \n"
canvas = Magick::Image.new(85, 75)
red = Magick::ImageList.new("public/images/stroke.png")
red.background_color = 'none';
cols = red.columns
rows = red.rows
gray = red.quantize(256, Magick::GRAYColorspace).modulate(2.5)
black = gray.modulate(0.001)
strokes={'y'=> black, 'n'=> red, '-' => gray}
draw = Magick::Draw.new
# The fifth stroke is diagonal
rotated = strokes[seq.at(4)]
rotated = rotated.resize(cols, rows * 1.5).rotate(-55)
draw.composite(-3, 0, rotated.columns, rotated.rows, rotated)
# draw four vertical lines
draw.composite(15, 0, cols, rows, strokes[seq.at(0)])
draw.composite(30, 0, cols, rows, strokes[seq.at(1)])
draw.composite(45, 0, cols, rows, strokes[seq.at(2)])
draw.composite(60, 0, cols, rows, strokes[seq.at(3)])
# Overpaint again if 'y' or 'n'
if (!seq.at(4).eql?('-'))
draw.composite(-3, 0, rotated.columns, rotated.rows, rotated)
end
draw.draw(canvas)
canvas.write('public/images/tally/' + seq + '.png')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment