waag/main.py

118 lines
3.8 KiB
Python
Raw Permalink Normal View History

2021-01-14 21:05:44 +01:00
#!/usr/bin/env python3
from __future__ import print_function
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
2021-01-14 22:27:19 +01:00
from wand.display import display
2021-01-14 21:05:44 +01:00
2021-03-28 13:41:32 +02:00
class CardColor:
def __init__(self, name, asset, hex_val):
self.name = name
self.hex_val = hex_val
self.asset = asset
2021-01-14 21:05:44 +01:00
def main():
2021-03-28 13:41:32 +02:00
colors = []
colors.append(CardColor('red', 'red', '#ff2929'))
colors.append(CardColor('green', 'green', '#00800e'))
colors.append(CardColor('blue', 'blue', '#0062f8'))
colors.append(CardColor('yellow', 'yellow', '#e2f800'))
special_cards = []
special_cards.append(CardColor('W', 'white', '#ffffff'))
special_cards.append(CardColor('N', 'white', '#ffffff'))
2021-01-14 21:05:44 +01:00
for color in colors:
2021-01-14 23:02:24 +01:00
for i in range(1, 14):
2021-01-14 22:27:19 +01:00
draw_card_face(color, i)
2021-01-14 21:05:44 +01:00
for sign in special_cards:
2021-03-28 13:41:32 +02:00
draw_card_face(sign, sign.name)
2021-01-14 21:05:44 +01:00
2021-01-14 22:27:19 +01:00
def draw_card_face(color, symbol):
2021-01-14 21:05:44 +01:00
with Image(filename='assets/wozard-card.png') as img:
2021-03-28 13:46:16 +02:00
draw_symbol(img, symbol, color.hex_val, 120, 190)
draw_symbol(img, symbol, color.hex_val, int(img.width - 120), 190)
2021-01-14 22:27:19 +01:00
img.flip() # Make mirrored text
2021-03-28 13:46:16 +02:00
draw_symbol(img, symbol, color.hex_val, 120, 190)
draw_symbol(img, symbol, color.hex_val, int(img.width - 120), 190)
2021-02-06 17:23:27 +01:00
draw_rune(img, color)
2021-03-28 13:41:32 +02:00
draw_mask(img)
if (symbol == "W"):
img.negate(channel="rgb")
2021-05-28 15:59:59 +02:00
draw_card_texture_overlay(img)
draw_card_trim(img)
2021-03-28 13:41:32 +02:00
save_img(img, color.asset, symbol)
if (symbol == "W"):
save_img(img, color.asset, 40)
if (symbol == "N"):
save_img(img, color.asset, 0)
2021-01-14 21:05:44 +01:00
2021-03-28 13:41:32 +02:00
def draw_symbol(img, symbol, hex_color, x, y):
2021-01-14 21:05:44 +01:00
with Drawing() as draw:
2021-01-15 22:14:43 +01:00
draw.font = 'DejaVu-Sans-Mono'
2021-03-28 13:46:16 +02:00
draw.font_size = 180
2021-03-28 12:30:52 +02:00
draw.font_weight = 1800
draw.stroke_color = Color('black')
2021-02-06 15:55:58 +01:00
draw.stroke_width = 5
2021-01-14 21:05:44 +01:00
draw.text_alignment = 'center'
2021-03-28 13:41:32 +02:00
draw.fill_color=hex_color
2021-01-14 21:05:44 +01:00
draw.text(x, y, str(symbol))
draw(img)
2021-01-14 22:27:19 +01:00
return img
2021-01-14 21:05:44 +01:00
2021-01-14 22:27:19 +01:00
def draw_rune(img, color):
2021-03-28 13:41:32 +02:00
with Image(filename='assets/{}.png'.format(color.asset)) as rune:
2021-02-06 15:11:31 +01:00
rune.resize(220,244)
2021-03-28 13:41:32 +02:00
rune.opaque_paint(target=Color("white"), fill=Color(color.hex_val), fuzz=0.66*img.quantum_range)
2021-01-14 22:27:19 +01:00
img.composite(
rune,
left=int((img.width - rune.width) / 2),
top=int((img.height - rune.height) / 2))
2021-02-06 15:55:58 +01:00
2021-01-14 21:05:44 +01:00
return img
2021-02-06 17:23:27 +01:00
def draw_card_trim(img):
with Image(filename='assets/card-trim.png') as trim:
img.composite(trim)
return img
2021-05-28 15:59:59 +02:00
def draw_card_texture_overlay(img):
with Image(filename='assets/card-texture-3.png') as texture:
img.composite(texture)
return img
2021-03-28 13:41:32 +02:00
def draw_mask(img):
2021-01-14 23:02:14 +01:00
# Mask with a pink outline. This pink outline is this replaced
# with a transparency layer before being returned
with Image(width=img.width, height=img.height, background=Color("#c300ff")) as mask:
with Drawing() as ctx:
ctx.fill_color = Color("black")
ctx.rectangle(left=0,
top=0,
width=mask.width,
height=mask.height,
radius=mask.width * 0.075)
ctx(mask)
img.composite_channel('all_channels', mask, 'screen')
img.opaque_paint(target=Color("#c300ff"), fill=Color("transparent"), fuzz=0.4*img.quantum_range)
2021-01-14 23:02:14 +01:00
return img
def save_img(img, color, symbol):
2021-01-15 21:46:08 +01:00
print('Created card {} {}'.format(color, symbol))
sizes = ['50', '25']
img.save(filename='output/card-{}-{}.png'.format(color, symbol))
for size in sizes:
img.resize(int(img.width / 2), int(img.height / 2))
img.save(filename='output/card-{}-{}-{}.png'.format(color, symbol, size))
2021-02-06 15:55:58 +01:00
2021-01-14 21:05:44 +01:00
main()