-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
executable file
·52 lines (40 loc) · 1.16 KB
/
generate.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
#!/usr/bin/env python3
text = 'Hello, world!'
margin_left = 0
margin_top = 0
radius = 8
gap = 5
stroke_width = 3
color = '#ffffff'
def ascii_to_binary(s):
codes = []
for c in s:
codes.append('{0:08b}'.format(ord(c)))
return codes
def circle(x, y):
print("""<ellipse
style="fill:none;stroke:{};stroke-width:{};stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path817"
cx="{}"
cy="{}"
rx="{}"
ry="{}"
/>""".format(color, stroke_width, x, y, radius, radius))
def vertical_stroke(cx, cy):
x = cx
y = cy - radius
height = 2 * radius
print("""<rect
style="fill:none;fill-opacity:1;stroke:{};stroke-width:{};stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
width="0.000001"
height="{}"
x="{}"
y="{}" />""".format(color, stroke_width, height, x, y))
for i, c in enumerate(ascii_to_binary(text)):
for j, d in enumerate(c):
x = margin_left + gap + radius + j * (gap + 2 * radius)
y = margin_top + gap + radius + i * (gap + 2 * radius)
if d == '0':
circle(x, y)
if d == '1':
vertical_stroke(x, y)