-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
93 lines (77 loc) · 2.99 KB
/
main.py
File metadata and controls
93 lines (77 loc) · 2.99 KB
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
import matplotlib.pyplot as plt
from patterns import Patterns
import numpy as np
from standard_transforms import translate_scale_rotate_transform
def draw_pattern(patterns_meta, filename=None):
"""
Draws multiple patterns on the same canvas after applying different sets of transformations.
:param patterns_meta: List of dictionaries, where each dictionary contains:
- 'pattern': A dictionary with 'transforms' (list of transformation functions)
and 'rotations' (number of rotations for the pattern).
- 'translations': Optional dictionary with 'x_offset', 'y_offset', 'scale_x', 'scale_y', 'rotation_angle'.
:param filename: Optional. If provided, saves the plot to the specified filename as an SVG.
"""
plt.figure(figsize=(8, 8))
for meta in patterns_meta:
pattern = meta['pattern']
transforms = pattern['transforms']
rotations = pattern['rotations']
# Optional translation parameters
translations = meta.get('translations', {})
x_offset = translations.get('x_offset', 0)
y_offset = translations.get('y_offset', 0)
scale_x = translations.get('scale_x', 1.0)
scale_y = translations.get('scale_y', 1.0)
rotation_angle = translations.get('rotation_angle', 0)
theta = np.linspace(0, 2 * np.pi * rotations, 50000) # Increased resolution
x = np.zeros_like(theta)
y = np.zeros_like(theta)
# Apply transformations for each set interleaved with optional translations
for transform_func in transforms:
# Apply the current pattern-specific transformation
x, y = transform_func(x, y, theta)
# Apply translation, scaling, and rotation
x, y = translate_scale_rotate_transform(
x, y, theta,
x_offset=x_offset,
y_offset=y_offset,
scale_x=scale_x,
scale_y=scale_y,
rotation_angle=rotation_angle
)
# Plot the pattern on the same canvas
plt.plot(x, y, lw=0.5, color='black')
# Set plot settings
plt.axis('equal')
plt.axis('off')
plt.tight_layout()
# Save the figure as an SVG file if a filename is provided
if filename:
plt.savefig(filename, format='svg')
# Display the plot
plt.show()
def generate_pattern():
patterns = Patterns()
patterns_meta = [
{
'pattern': patterns.get_pattern('croissant'),
'translations': {
'x_offset': 293,
'y_offset': 88,
'scale_x': 0.82,
'scale_y': 0.8,
'rotation_angle': 0
}
},
{
'pattern': patterns.get_pattern('meta_spiral'),
# No translations (this pattern stays in its default position and size)
}
]
draw_pattern(patterns_meta, filename="foo.svg")
def main():
generate_pattern()
if __name__ == "__main__":
main()
#
#