64 lines
2.4 KiB
Python
64 lines
2.4 KiB
Python
# Bake snake textures. Working resolution 80px, saved at 20px (cell size).
|
|
# Base tiles: body, head (eyes), apple, plus rotated variants written into src/common/tex/.
|
|
import os
|
|
from PIL import Image, ImageDraw
|
|
|
|
TILE = 80
|
|
OUT = os.path.expanduser('~/vela-snake/src/common/tex')
|
|
os.makedirs(OUT, exist_ok=True)
|
|
|
|
def rr(d, box, rad, fill):
|
|
d.rounded_rectangle(box, radius=rad, fill=fill)
|
|
|
|
def body():
|
|
W = TILE
|
|
img = Image.new('RGBA', (W, W), (0, 0, 0, 0))
|
|
d = ImageDraw.Draw(img)
|
|
rr(d, (0, 10, W, W - 10), 14, (60, 183, 90, 255))
|
|
for cx, cy in ((18, 26), (W - 30, W - 38)):
|
|
d.ellipse((cx - 14, cy - 14, cx + 14, cy + 14), fill=(46, 160, 74, 255))
|
|
d.ellipse((cx - 6, cy - 6, cx + 6, cy + 6), fill=(60, 183, 90, 255))
|
|
return img
|
|
|
|
def head():
|
|
W = TILE
|
|
img = Image.new('RGBA', (W, W), (0, 0, 0, 0))
|
|
d = ImageDraw.Draw(img)
|
|
rr(d, (10, 12, W, W - 12), 22, (64, 188, 110, 255))
|
|
d.ellipse((W - 52, 24, W - 32, 44), fill=(255, 255, 255, 255))
|
|
d.ellipse((W - 46, 30, W - 38, 38), fill=(30, 30, 30, 255))
|
|
return img
|
|
|
|
def apple():
|
|
W = TILE
|
|
img = Image.new('RGBA', (W, W), (0, 0, 0, 0))
|
|
d = ImageDraw.Draw(img)
|
|
d.ellipse((8, 14, W - 8, W - 6), fill=(224, 62, 62, 255))
|
|
d.ellipse((16, 24, 34, 42), fill=(255, 255, 255, 70))
|
|
d.polygon(((W // 2 - 4, 12), (W // 2 + 18, 4), (W // 2 + 10, 16)), fill=(56, 128, 56, 255))
|
|
d.rectangle((W // 2 - 3, 10, W // 2 + 1, 18), fill=(90, 60, 30, 255))
|
|
return img
|
|
|
|
def head_open():
|
|
W = TILE
|
|
img = head()
|
|
d = ImageDraw.Draw(img)
|
|
d.rectangle((0, 0, 10, W), fill=(0, 0, 0, 0))
|
|
d.rectangle((10, 36, 34, 44), fill=(226, 62, 62, 255))
|
|
d.polygon(((10, 36), (26, 28), (30, 40)), fill=(226, 62, 62, 255))
|
|
return img
|
|
|
|
def save20(img, name):
|
|
img.resize((20, 20), Image.LANCZOS).save(os.path.join(OUT, name))
|
|
|
|
# base tiles: body + head drawn mouth-E (E = right); rotated variants cover all directions
|
|
b = body()
|
|
save20(b, 'body.png') # 4-way base body tile
|
|
h = head_open() # head with tongue + eyes, W edge open
|
|
save20(h, 'head_e.png') # facing east
|
|
save20(h.transpose(Image.FLIP_LEFT_RIGHT), 'head_w.png')
|
|
save20(h.transpose(Image.ROTATE_90), 'head_n.png') # E->N under ccw
|
|
save20(h.transpose(Image.ROTATE_90).transpose(Image.FLIP_TOP_BOTTOM), 'head_s.png')
|
|
save20(apple(), 'apple.png')
|
|
print('base tiles done')
|