-
Notifications
You must be signed in to change notification settings - Fork 0
/
soylent-green-svg.py
executable file
·55 lines (40 loc) · 1.27 KB
/
soylent-green-svg.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
#!/usr/bin/env python
#
# https://github.com/mozman/svgwrite
# https://svgwrite.readthedocs.io/en/latest/
#
import svgwrite
from six.moves import range
def endlessStringByN(origStr, n):
assert n > 0
s = ''
while True:
if len(s) < n:
s += origStr
yield s[:n]
s = s[n:]
def createSVG(drawFn, fileName, *args):
dwg = svgwrite.Drawing(fileName, profile='tiny')
drawFn(dwg, *args)
dwg.save(pretty=True)
def soylentGreen(dwg, xNum, yNum, xWidth, yWidth):
lineKwArgs = {
'stroke' : svgwrite.rgb(100, 100, 100, '%')
}
xSize = xNum * xWidth
ySize = yNum * yWidth
print('Total size is', xSize, 'mm x', ySize, 'mm')
for x in range(xNum + 1):
x = x * xWidth
dwg.add(dwg.line((x, 0), (x, xSize), **lineKwArgs))
for y in range(yNum + 1):
y = y * yWidth
dwg.add(dwg.line((0, y), (ySize, y), **lineKwArgs))
letters = endlessStringByN("soylentgreen", 2)
for x in range(xNum):
for y in range(yNum):
xPos = (x + 0.5) * xWidth
yPos = (y + 0.5) * yWidth
# TODO: Make text centered
dwg.add(dwg.text(letters.__next__(), insert=(xPos, yPos), fill='red'))
createSVG(soylentGreen, 'soylent-green.svg', 10, 10, 20, 20)