Skip to content

Instantly share code, notes, and snippets.

@ultraist
Created May 21, 2011 02:19
Show Gist options
  • Save ultraist/984159 to your computer and use it in GitHub Desktop.
Save ultraist/984159 to your computer and use it in GitHub Desktop.
テキトウなトランプ画像を作る
# http://f82cbdfd9f2d880db8b9443b4e84320b.gazou.me/large.png
require 'rubygems'
require 'RMagick'
require 'fileutils'
WIDTH = 80
MARK_WIDTH = 11
MARKS = [
[
0,0,0,0,0,1,0,0,0,0,0,
0,0,0,0,1,1,1,0,0,0,0,
0,0,0,1,1,1,1,1,0,0,0,
0,0,1,1,1,1,1,1,1,0,0,
0,1,1,1,1,1,1,1,1,1,0,
1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,
0,1,1,1,0,1,0,1,1,1,0,
0,0,1,0,0,1,0,0,1,0,0,
0,0,0,0,1,1,1,0,0,0,0,
0,0,1,1,1,1,1,1,1,0,0
],
[
0,0,0,0,0,0,0,0,0,0,0,
0,0,1,1,0,0,0,1,1,0,0,
0,1,1,1,1,0,1,1,1,1,0,
1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,
0,1,1,1,1,1,1,1,1,1,0,
0,0,1,1,1,1,1,1,1,0,0,
0,0,0,1,1,1,1,1,0,0,0,
0,0,0,0,1,1,1,0,0,0,0,
0,0,0,0,0,1,0,0,0,0,0
],
[
0,0,0,0,0,1,0,0,0,0,0,
0,0,0,0,1,1,1,0,0,0,0,
0,0,0,1,1,1,1,1,0,0,0,
0,0,1,1,1,1,1,1,1,0,0,
0,1,1,1,1,1,1,1,1,1,0,
1,1,1,1,1,1,1,1,1,1,1,
0,1,1,1,1,1,1,1,1,1,0,
0,0,1,1,1,1,1,1,1,0,0,
0,0,0,1,1,1,1,1,0,0,0,
0,0,0,0,1,1,1,0,0,0,0,
0,0,0,0,0,1,0,0,0,0,0
],
[
0,0,0,0,1,1,1,0,0,0,0,
0,0,0,1,1,1,1,1,0,0,0,
0,0,0,1,1,1,1,1,0,0,0,
0,1,1,0,1,1,1,0,1,1,0,
1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,0,1,0,1,1,1,1,
0,1,1,0,0,1,0,0,1,1,0,
0,0,0,0,1,1,1,0,0,0,0,
0,0,1,1,1,1,1,1,1,0,0
]
]
NAMES = ['S','H','D','C']
COLORS = [
Magick::Pixel.new(0,0,0),
Magick::Pixel.new(Magick::MaxRGB,0,0),
Magick::Pixel.new(Magick::MaxRGB,0,0),
Magick::Pixel.new(0,0,0)
]
NUMBERS = ['A','2','3','4','5','6','7','8','9','10','J','Q','K']
FONT = 'fixed'
FONT_SIZE = MARK_WIDTH
def draw_mark(img, x, y, mark, color)
mark.each_index do |i|
py = i / MARK_WIDTH
px = i % MARK_WIDTH
if (mark[i] != 0)
img.pixel_color(x + px, y + py, color)
end
end
end
FileUtils.mkdir_p("cards")
MARKS.each_index do |i|
mark = MARKS[i]
color = COLORS[i]
name = NAMES[i]
NUMBERS.each do |num|
canvas = Magick::ImageList.new
canvas.new_image(WIDTH, (WIDTH * ((1.0 + Math.sqrt(5.0)) / 2)).to_i)
gc = Magick::Draw.new
gc.fill('#FFFFFF')
gc.draw(canvas)
gc.annotate(canvas, 0, 0, 2 + (FONT_SIZE ) / 2, 2 + FONT_SIZE, num) do
self.font = FONT
self.fill = color
self.align = Magick::CenterAlign
self.stroke = 'transparent'
self.pointsize = FONT_SIZE
end
draw_mark(canvas, 2, 18, mark, color)
canvas.flip!.flop!
gc.annotate(canvas, 0, 0, 2 + (FONT_SIZE ) / 2, 2 + FONT_SIZE, num) do
self.font = FONT
self.fill = color
self.align = Magick::CenterAlign
self.stroke = 'transparent'
self.pointsize = FONT_SIZE
end
draw_mark(canvas, 2, 18, mark, color)
canvas.border!(1, 1, 'black')
canvas.write("cards/#{name}-#{num}.png")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment