-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtransform.py
52 lines (43 loc) · 1.2 KB
/
transform.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
"""
Tutorial:
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform
Usage:
PYTHONPATH=. python3 examples/transform.py > examples/transform.svg
xdg-open examples/transform.svg
We use functions instead of <g> and <use>
because it gives a better control over types.
"""
from __future__ import annotations
import svg
def heart_path() -> list[svg.PathData]:
return [
svg.M(10, 30),
svg.Arc(20, 20, 0, False, True, x=50, y=30),
svg.Arc(20, 20, 0, False, True, x=90, y=30),
svg.Q(90, 60, 50, 90),
svg.Q(10, 60, 10, 30),
svg.Z(),
]
def draw() -> svg.SVG:
return svg.SVG(
viewBox=svg.ViewBoxSpec(-40, 0, 150, 100),
elements=[
svg.Path(
d=heart_path(),
fill="grey",
transform=[
svg.Rotate(-10, 50, 100),
svg.Translate(-36, 45.5),
svg.SkewX(40),
svg.Scale(1, 0.5),
],
),
svg.Path(
d=heart_path(),
fill="none",
stroke="red",
),
],
)
if __name__ == '__main__':
print(draw())