-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathpunctuation.py
90 lines (69 loc) · 2.56 KB
/
punctuation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import string
import math
import sys
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
## VARIABLES
# size of output canvas in pixels
canvasHeight = 8000;
canvasWidth = 8000;
# pixel border width
trim = 100;
font1size = 48;
font2size = 72;
# number of symbols to be output on each line
symbolsPerLine = 70;
# and the number of lines
linesOfText = 70;
# symbolsPerLine = int(math.floor(math.sqrt(len(punct))));
# linesOfText = int(math.floor(len(punct)/symbolsPerLine));
if (len(sys.argv) > 1):
bookname = sys.argv[1]
else:
bookname = 'ulysses'
file = open(bookname + '.txt','r')
txt = file.read()
file.close()
include = set(string.punctuation)
def getPunctuation(s):
return ''.join(ch for ch in s if ch in include)
punct = getPunctuation(txt);
# file = open('blood-punct.txt','w')
file = open(bookname + '-punct.txt','w')
file.write(punct)
file.close()
deltaW = (canvasWidth - trim*2)/symbolsPerLine
deltaH = (canvasHeight - trim*2)/linesOfText
bkgColor = (238,212,187)
bkgColor = (255,255,255)
img = Image.new("RGB", [canvasWidth,canvasHeight], bkgColor)
draw = ImageDraw.Draw(img)
# font from (SEE LICENSE!): http://www.fontsquirrel.com/fonts/glacial-indifference
font1 = ImageFont.truetype("GlacialIndifference-Bold.otf", font1size)
font2 = ImageFont.truetype("GlacialIndifference-Bold.otf", font2size)
# transitionFill = (0,0,0);
# endSentenceFill = (125,0,0);
# parentheticalFill = (235,235,235);
# in case you want to change by transition
transitionFill = (0,0,0);
endSentenceFill = (0,0,0);
parentheticalFill = (0,0,0);
# getTextSize
for ii in range(linesOfText):
for jj in range(symbolsPerLine):
symb = punct[jj + ii*symbolsPerLine]
if (symb == '.'):
draw.text((trim + jj*deltaW,trim + ii*deltaH - round(font2size/4)), symb,fill=endSentenceFill,font=font2)
elif (symb == ','):
draw.text((trim + jj*deltaW,trim + ii*deltaH - round(font2size/4)), symb,fill=transitionFill,font=font2)
elif (symb == '!') or (symb == '?'):
draw.text((trim + jj*deltaW,trim + ii*deltaH), symb,fill=endSentenceFill,font=font2)
elif (symb == '"') or (symb == '\'') or (symb == '(') or (symb == ')') or (symb == '[') or (symb == ']'):
draw.text((trim + jj*deltaW,trim + ii*deltaH), symb,fill=parentheticalFill,font=font2)
elif (symb == ';') or (symb == '-') or (symb == ':'):
draw.text((trim + jj*deltaW,trim + ii*deltaH), symb,fill=transitionFill,font=font2)
else:
draw.text((trim + jj*deltaW,trim + ii*deltaH), symb,fill="green",font=font2)
img.save(bookname + '.png')
print(len(punct))