-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsquares.py
68 lines (48 loc) · 1.61 KB
/
squares.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
import svgwrite
import svgutils.transform as st
import random
class Dwg():
def __init__(self,height=10, width=10, fill = "rgb(255,255,44)"):
self.width = height
self.height = width
self.dwg = svgwrite.Drawing(
'test.svg',
size=(400, 400),
profile='tiny',
stroke_width=0.5,
stroke='black',
stroke_opacity=1.0,
fill = fill
)
def draw_rectangle(self):
for x in range(0, self.width):
for y in range(0, self.height):
position_modifier_x = (random.random() - 0.5) * (x + (y * self.width))
position_modifier_y = (random.random() - 0.5) * (x + (y * self.height))
self.dwg.add(self.dwg.rect(
(
x * 10 + position_modifier_x,
y * 10 + position_modifier_y
),
(self.width,self.height)
))
def save_as(self,filename):
self.dwg.saveas(filename)
# main
if __name__ == "__main__":
d1 = Dwg()
d1.draw_rectangle()
d1.save_as("first.svg")
d2 = Dwg(height=15, fill = "rgb(255,255,214)")
d2.draw_rectangle()
d2.save_as("second.svg")
d3 = Dwg(width=15, fill = "rgb(255,85,214)")
d3.draw_rectangle()
d3.save_as("third.svg")
template = st.fromfile('first.svg')
second_svg = st.fromfile('second.svg')
third_svg = st.fromfile('third.svg')
template.append(second_svg)
template.append(third_svg)
template.save('merged.svg')
# https://stackoverflow.com/a/23482756/12670189