Skip to content

Instantly share code, notes, and snippets.

@erikpukinskis
Created December 16, 2009 23:58
Show Gist options
  • Save erikpukinskis/258357 to your computer and use it in GitHub Desktop.
Save erikpukinskis/258357 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'RMagick'
require 'ruby-debug'
layout = "QWERT
YUIOP
ASDFG
HJKLNM
ZXCVB"
COLS = 30
CHAR_WIDTH = 30
LEADING = -6
WIDTH_TOTAL = CHAR_WIDTH + LEADING
LINE_HEIGHT = 27
$coords = {}
lines = layout.split("\n")
(0..4).each do |y|
(0..lines[y].length-1).each do |x|
char = lines[y][x,1]
$coords[char] = [x,y]
end
end
string = <<-EOS
THE BILL OF RIGHTS
Amendment I
Congress shall make no law respecting an establishment of
religion, or prohibiting the free exercise thereof; or
abridging the freedom of speech, or of the press; or the
right of the people peaceably to assemble, and to petition
the government for a redress of grievances.
Amendment II
A well regulated militia, being necessary to the security
of a free state, the right of the people to keep and bear
arms, shall not be infringed.
Amendment III
No soldier shall, in time of peace be quartered in any house,
without the consent of the owner, nor in time of war, but
in a manner to be prescribed by law.
Amendment IV
The right of the people to be secure in their persons, houses,
papers, and effects, against unreasonable searches and seizures,
shall not be violated, and no warrants shall issue, but upon
probable cause, supported by oath or affirmation, and
particularly describing the place to be searched, and the
persons or things to be seized.
Amendment V
No person shall be held to answer for a capital, or otherwise
infamous crime, unless on a presentment or indictment of a grand
jury, except in cases arising in the land or naval forces,
or in the militia, when in actual service in time of war
or public danger; nor shall any person be subject for the
same offense to be twice put in jeopardy of life or limb;
nor shall be compelled in any criminal case to be a witness
against himself, nor be deprived of life, liberty, or property,
without due process of law; nor shall private property be
taken for public use, without just compensation.
Amendment VI
In all criminal prosecutions, the accused shall enjoy the right
to a speedy and public trial, by an impartial jury of the state
and district wherein the crime shall have been committed, which
district shall have been previously ascertained by law, and
to be informed of the nature and cause of the accusation;
to be confronted with the witnesses against him; to have
compulsory process for obtaining witnesses in his favor,
and to have the assistance of counsel for his defense.
Amendment VII
In suits at common law, where the value in controversy shall
exceed twenty dollars, the right of trial by jury shall be
preserved, and no fact tried by a jury, shall be otherwise
reexamined in any court of the United States, than according
to the rules of the common law.
Amendment VIII
Excessive bail shall not be required, nor excessive fines
imposed, nor cruel and unusual punishments inflicted.
Amendment IX
The enumeration in the Constitution, of certain rights, shall
not be construed to deny or disparage others retained by the people.
Amendment X
The powers not delegated to the United States by the
Constitution, nor prohibited by it to the states, are
reserved to the states respectively, or to the people.
EOS
{
"." => " xx ",
"," => " xck ",
"?" => " yqtgdc ",
"!" => " xw "
}.each_pair do |char, replacement|
string = string.gsub(char, replacement)
end
string = string.gsub('[^A-Za-z]', ' \1 ')
string = string.upcase
string = string.gsub(/[^A-Z ]/, '')
words = string.split(" ")
width = WIDTH_TOTAL * COLS
height = LINE_HEIGHT * ((words.count/COLS).ceil + 1)
canvas = Magick::Image.new(width, height)
gc = Magick::Draw.new
gc.stroke_width(2)
$xoff = 0
$yoff = 0
def draw_letter(str, gc)
first = true
(0..str.length-2).each do |i|
char = str[i,1]
if $coords[char]
next_char = str[i+1,1]
x1,y1 = $coords[char]
x2,y2 = $coords[next_char]
#puts "#{char}:[#{x1},#{y1}] to #{next_char}:[#{x2},#{y2}]"
x1 = x1*5+2+WIDTH_TOTAL*$xoff
y1 = y1*5+2+LINE_HEIGHT*$yoff
x2 = x2*5+2+WIDTH_TOTAL*$xoff
y2 = y2*5+2+LINE_HEIGHT*$yoff
if first
gc.stroke('blue')
gc.circle(x1,y1,x1-1.5,y1)
first = false
end
gc.stroke('black')
gc.line(x1,y1,x2,y2)
end
end
inc = (str == "ZQTB") ? 2 : 1
$xoff += inc
if $xoff > COLS
$xoff = 0
$yoff += 1
end
end
words.each_with_index do |word,word_index|
draw_letter(word, gc)
end
gc.draw(canvas)
canvas.write('out.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment