Created
April 4, 2020 21:42
-
-
Save infval/45d10fbc4588f3f62de113d7ac8f1228 to your computer and use it in GitHub Desktop.
Draw Round Numbers (Circle) | Python 3 + PIL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from PIL import Image | |
from PIL import ImageDraw | |
FACTOR = 4 # Super sampling | |
H = 256 * FACTOR | |
HGAP = 16 * FACTOR | |
WLINE = 16 * FACTOR | |
numbers = ( | |
r"/_\/-\ ", # 0 | |
r"/ \ ", # 1 | |
r" -\ -\-", # 2 | |
r"/- -\-", # 3 | |
r"/ / \-", # 4 | |
r"/- /- -", # 5 | |
r"/_\/- -", # 6 | |
r"/ -\ ", # 7 | |
r"/_\/-\-", # 8 | |
r"/_ /-\-", # 9 | |
) | |
def draw_number(draw, x, segments): | |
angle = 0 | |
for s in segments[:6]: | |
if s != ' ': | |
draw.arc((x, 0, x+(H-1), H-1), angle, angle + 60, 'black', width=WLINE) | |
angle += 60 | |
if segments[6] != ' ': | |
draw.line((x, H//2-1, x+(H-2), H//2-1), 'black', width=WLINE) | |
width = (H+HGAP)*10 | |
height = H | |
img = Image.new('RGBA',(width, height)) | |
draw = ImageDraw.Draw(img) | |
for i, n in enumerate(numbers): | |
draw_number(draw, i * (H+HGAP), n) | |
img = img.resize((width//FACTOR, height//FACTOR), Image.LANCZOS) | |
img.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment