①Pythonで画像から色情報抜き出す
(1)画像を準備(縦横400pixcel(マス目は40x40))
(2)Pythonで色情報を抜き出す
out_img.py
#coding: utf-8
from PIL import Image
im = Image.open("./400x400.jpg")
rgb_im = im.convert('RGB')
f = open('./Ein400x400.txt', 'w')
for i in range(5,401,10):
f.write("(\n")
for j in range(5,401,10):
r, g, b = rgb_im.getpixel((i, j))
f.write("("+str(((i/5)+1)/2) +"," + str(((j/5)+1)/2) + "," + str(r) + "),\n")
f.write("),\n")
f.close()
②PythonでShade3Dスクリプトで濃淡絵を書く
(1)スクリプト
script_for_shade3d.py
import math
import random
scene = xshade.scene()
scene.begin_creating()
a = ((
(1,1,66),
(1,2,64),
〜略
(40,39,130),
(40,40,120),
),
)
for n in range(0,40,1):
for m in range(0,40,1):
s = 0.5
x = n
y = 0
z = m
hgt = 8 - a[n][m][2] * 8 / 255
scene.create_primitive_box(None, 3, True, 1, 1, 1, [x+s, y-s, z-s], [x+s, y-s, z+s], [x-s,y-s, z+s], [x-s, y-s, z-s], [0, 2+hgt, 0], True, True)
scene.end_creating()
(2)Shade3D