2007/11/09(金) [n年前の日記]
#9 [prog] テクスチャ貼り付け確認用のテクスチャを作成
パノラマ画像変換・表示ツールの類がどのような結果画像を出力するのか確認したかったので、升目を並べた画像を作成。
さすがにCGツールを使って手作業で作るのは辛そうだったので、Python + PIL でスクリプトを書いた。こんな感じ。
こんな感じの画像を出力。
さすがにCGツールを使って手作業で作るのは辛そうだったので、Python + PIL でスクリプトを書いた。こんな感じ。
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# テクスチャ貼り付け確認用、のテクスチャ画像を作成するスクリプト
# フォントファイルは Windows/Fonts/ からコピーしてきた
from PIL import Image, ImageDraw, ImageFont
width = 1024 # 画像横幅
height = 512 # 画像縦幅
xw = 32 # 1マスの幅
yh = 32 # 1マスの高さ
outfilename = "test.bmp" # 出力ファイル名
fontname = "arial.ttf" # フォントファイル名
fontsize = 12 # フォントサイズ
# マスを色分けする際のカラーリスト
colorlist = [
(0x40,0x40,0xff),
(0x00,0xff,0x00),
(0x00,0xff,0xff),
(0xff,0x00,0x00),
(0xff,0x00,0xff),
(0xff,0xff,0x00),
(0xff,0xff,0xff),
(0x80,0x80,0x80)
]
def makeImage():
# 新規画像作成
img = Image.new("RGB", (width, height), (0,0,0))
# 画像に対して描画するためのモニャモニャ
draw = ImageDraw.Draw(img)
# 画像に対して文字を書き込むためのモニャモニャ
font = ImageFont.truetype(fontname, fontsize)
colindex = 0
numberindex = 0
for y in range(height/yh):
y0 = y * yh
for x in range(width/xw):
x0 = x * xw
col = colorlist[colindex]
str = unicode("%03d" % numberindex, "shift_jis")
# マスを塗りつぶす
draw.rectangle((x0,y0,x0+xw,y0+yh), fill=col)
# 文字を書く
draw.text((x0+4,y0+4), str, font=font, fill=0)
# マスの枠を描く
draw.rectangle((x0,y0,x0+xw,y0+yh), outline=(0,0,0))
colindex += 1
colindex %= len(colorlist)
numberindex += 1
# 画像をファイルとして保存
img.save(outfilename)
def main():
makeImage()
print "complete."
if __name__ == "__main__":
main()
こんな感じの画像を出力。
[ ツッコむ ]
以上です。
