-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.py
95 lines (76 loc) · 2.04 KB
/
demo.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
91
92
93
94
95
import math
from prosvg.svg import *
# Color definitions
black = '#1c1b19'
white = '#fce8c3'
red = '#f75341'
blue = '#0aaeb3'
yellow = '#fbb829'
green = '#98bc37'
magenta = '#ff5c8f'
tau = 2 * math.pi
img = Drawing(800, 600)
img.fill(black)
# Line Paths
axis = Path(Stroke(white, 5))
axis.M(0, img.center.y).H(img.width)
axis.M(img.center.x, 0).v(img.height)
# Circle
A = img.center + Point(100, -100)
circle = Circle(A.x, A.y, 50, Fill(blue))
# Rectangle
rect = Rect(img.center.x - 350, img.center.y - 50, 80, 120, Fill(red))
# Polygons
shape = RegularPolygon(
*(img.center + Point(-100, 120)),
*(img.center + Point(-100, 80)),
5,
Fill(green)
)
bottomRight = Point(img.width, img.height)
shape2 = Polygon(
[bottomRight, bottomRight + Point(0, -50), bottomRight + Point(-50,0)],
Fill(white)
)
# Line
line = Line(
*(img.center + Point(-150, -150)),
*(img.center + Point(150, 150)),
Stroke(green, 5).dashArray(0,10).lineCap('round')
)
# Parametric Equations
def func(t):
center = img.center + Point(150, 150)
return center + Polar(100 + 25 * math.cos(6*t), t)
def func2(t):
center = img.center + Point(-150, -150)
return center + (Polar(50, t) + Polar(25, 2*t)).rotate(tau/4)
plot = Path(Stroke(yellow, 5))
plot.parametric(func, 0, 2 * math.pi, n=60)
heart = Path(Fill(magenta))
heart.parametric(func2, 0, 2 * math.pi, n=60)
# Text
text = Text(20, 60, 'PROGRAMMATIC\nSVG', Font('Lexend Deca', 40, white))
# Arcs
arc = Path(Fill(white))
arc.slice(*(img.center + Point(300, -100)), 50, 50, 0, tau*0.75)
arc2 = Path(Stroke(white, 5))
arc2.arc(*(img.center + Point(300, -200)), 50, 50, tau/2, tau)
arc2.id = 'clone'
# Some clones created with the <use> tag
arc3 = arc2.clone(x = -20)
arc4 = arc2.clone(x = -40)
# Ellipse
B = img.center + Point(-50, 50)
ellipse = Ellipse(B.x, B.y, 100, 50, FillStroke(white + '80', white, 5))
ellipse.rotate(tau / 12)
# Add Objects
img.add(
axis, circle, rect,
shape, shape2,
plot, line, heart,
arc, arc2, arc3, arc4,
ellipse, text
)
# Write to File
img.write('demo.svg')