-
Notifications
You must be signed in to change notification settings - Fork 0
/
svg_generate.py
38 lines (29 loc) · 1.32 KB
/
svg_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
def svg(*items):
""" Відкриваємо та закриваємо тіло svg файлу
та заповнюємо нутрощі елементами.
"""
ret = '<svg>'
for i in items:
ret += i
return ret + '</svg>'
def rect(x, y, w, h, fill):
""" Вставляємо значення зі змінних у прямокутник.
"""
return '<rect x="{}" y="{}" width="{}" height="{}" fill="{}"/>'.format(x, y,
w, h,
fill)
def circ(x, y, r, fill='black'):
""" Вставляємо значення зі змінних у коло.
"""
return '<circle cx="{}" cy="{}" r="{}" fill="{}"/>'.format(x, y, r, fill)
def group(*items, fill='', stroke='', transform=''):
ret = '<g fill="{}" stroke="{}" transform="{}">'
for i in items:
ret += i
ret += '</g>'
return ret.format(fill, stroke, transform)
svg(group(circ(120, 120, 40, 'red'),
rect(80, 80, 25, 60, 'green'),
fill='black',
transform='rotate(30)'))
# => '<svg><g fill="black" stroke="" transform="rotate(30)"><circle cx="120" cy="120" r="40" fill="red"/><rect x="80" y="80" width="25" height="60" fill="green"/></g></svg>'