waag/main.py

75 lines
2.5 KiB
Python
Raw 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
def main():
colors = ['red', 'green', 'blue', 'yellow']
special_cards = ['W', 'N']
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-01-14 22:27:19 +01:00
draw_card_face('white', sign)
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:
img = draw_symbol(img, symbol, color, 90, 130)
img = draw_symbol(img, symbol, color, int(img.width - 90), 130)
2021-01-14 22:27:19 +01:00
img.flip() # Make mirrored text
2021-01-14 21:05:44 +01:00
img = draw_symbol(img, symbol, color, 90, 130)
img = draw_symbol(img, symbol, color, int(img.width - 100), 130)
2021-01-14 22:27:19 +01:00
img = draw_rune(img, color)
2021-01-14 23:02:14 +01:00
draw_mask(img, color)
save_img(img, color, symbol)
2021-01-14 21:05:44 +01:00
def draw_symbol(img, symbol, color, x, y):
with Drawing() as draw:
2021-01-15 22:05:16 +01:00
draw.font = 'League_Gothic'
2021-01-14 21:05:44 +01:00
draw.font_size = 100
draw.stroke_color = Color('black')
draw.stroke_width = 3
2021-01-14 21:05:44 +01:00
draw.text_alignment = 'center'
draw.fill_color=Color(color)
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):
with Image(filename='assets/{}.png'.format(color)) as rune:
rune.resize(110,122)
img.composite(
rune,
left=int((img.width - rune.width) / 2),
top=int((img.height - rune.height) / 2))
2021-01-14 21:05:44 +01:00
return img
2021-01-14 23:02:14 +01:00
def draw_mask(img, color):
# 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))
img.save(filename='output/card-{}-{}.png'.format(color, symbol))
2021-01-14 21:05:44 +01:00
main()