-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_site.py
executable file
·282 lines (252 loc) · 7.44 KB
/
generate_site.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/usr/bin/env python3
import svgwrite
from dataclasses import dataclass
from typing import Optional, Tuple, List
from jinja2 import Environment, FileSystemLoader
import os
@dataclass
class PatternPoint:
origin: Tuple[float, float]
control_ccw: Optional[Tuple[float, float]]
control_cw: Optional[Tuple[float, float]]
def scale(self, factor: float) -> 'PatternPoint':
"""Scale the pattern point by a given factor."""
origin = (self.origin[0] * factor, self.origin[1] * factor)
control_ccw = (self.control_ccw[0] * factor, self.control_ccw[1] * factor) if self.control_ccw else None
control_cw = (self.control_cw[0] * factor, self.control_cw[1] * factor) if self.control_cw else None
return PatternPoint(origin, control_ccw, control_cw)
@dataclass
class CupSize:
size_no: int
over_breast_measurement: str
def line_length(self) -> float:
size_index = self.size_no - 1
return line_length_base + size_index * line_length_step
def scale_factor(self) -> float:
return self.line_length() / reference_cup_size.line_length()
# Pattern points data
pattern_points = [
PatternPoint(
origin=(0.0, 0.0),
control_ccw=(14.0407, 25.0918),
control_cw=(-14.5372, 22.8171),
),
PatternPoint(
origin=(-65.0, 57.7614),
control_ccw=(-40.1933, 43.6463),
control_cw=(-83.4987, 37.6504),
),
PatternPoint(
origin=(-97.7787, -29.8535),
control_ccw=(-106.1128, 11.0309),
control_cw=(-96.0463, -38.3517),
),
PatternPoint(
origin=(-88.9743, -54.2035),
control_ccw=(-92.8233, -46.481),
control_cw=(-67.1478, -60.2205),
),
PatternPoint(
origin=(-41.9367, -107.5931),
control_ccw=(-57.6472, -75.3583),
control_cw=None),
PatternPoint(
origin=(78.7962, -46.7356),
control_ccw=None,
control_cw=(100.4121, -14.4459),
),
PatternPoint(
origin=(62.7811, 59.2765),
control_ccw=(87.6192, 32.6349),
control_cw=(39.5943, 43.9509),
),
]
# Base "line 1" length for size 4 (11.57 cm)
line_length_base = 11.57
# Step for "line 1" (1.07 cm)
line_length_step = 1.07
# Defining the cup sizes with their ratios and measurements
cup_sizes = [
CupSize(
size_no=1,
over_breast_measurement="14.1cm to 14.7cm",
),
CupSize(
size_no=2,
over_breast_measurement="15.8cm to 16.4cm",
),
CupSize(
size_no=3,
over_breast_measurement="17.5cm to 18.1cm",
),
CupSize(
size_no=4,
over_breast_measurement="19.2cm to 19.8cm",
),
CupSize(
size_no=5,
over_breast_measurement="20.9cm to 21.5cm",
),
CupSize(
size_no=6,
over_breast_measurement="22.6cm to 23.2cm",
),
CupSize(
size_no=7,
over_breast_measurement="24.3cm to 24.9cm",
),
CupSize(
size_no=8,
over_breast_measurement="26.0cm to 26.6cm",
),
CupSize(
size_no=9,
over_breast_measurement="27.7cm to 28.3cm",
),
CupSize(
size_no=10,
over_breast_measurement="29.4cm to 30.0cm",
),
CupSize(
size_no=11,
over_breast_measurement="31.1cm to 31.7cm",
),
CupSize(
size_no=12,
over_breast_measurement="32.8cm to 33.4cm",
),
CupSize(
size_no=13,
over_breast_measurement="34.5cm to 35.1cm",
),
CupSize(
size_no=14,
over_breast_measurement="36.2cm to 36.8cm",
),
CupSize(
size_no=15,
over_breast_measurement="37.9cm to 38.5cm",
),
CupSize(
size_no=16,
over_breast_measurement="39.6cm to 40.2cm",
),
CupSize(
size_no=17,
over_breast_measurement="41.3cm to 41.9cm",
),
CupSize(
size_no=18,
over_breast_measurement="43.0cm to 43.6cm",
),
CupSize(
size_no=19,
over_breast_measurement="44.7cm to 45.3cm",
),
CupSize(
size_no=20,
over_breast_measurement="46.4cm to 47.0cm",
),
CupSize(
size_no=21,
over_breast_measurement="48.1cm to 48.7cm",
),
CupSize(
size_no=22,
over_breast_measurement="49.8cm to 50.4cm",
),
CupSize(
size_no=23,
over_breast_measurement="51.5cm to 52.1cm",
),
CupSize(
size_no=24,
over_breast_measurement="53.2cm to 53.8cm",
),
CupSize(
size_no=25,
over_breast_measurement="54.9cm to 55.5cm",
),
CupSize(
size_no=26,
over_breast_measurement="56.6cm to 57.2cm",
),
CupSize(
size_no=27,
over_breast_measurement="58.3cm to 58.9cm",
),
CupSize(
size_no=28,
over_breast_measurement="60.0cm to 60.6cm",
),
CupSize(
size_no=29,
over_breast_measurement="61.7cm to 62.3cm",
),
]
# The reference size (size 4)
reference_cup_size = cup_sizes[3]
def scale_pattern_points(pattern_points: List[PatternPoint], scale_factor: float) -> List[PatternPoint]:
"""Scale the pattern points by a given factor."""
return [point.scale(scale_factor) for point in pattern_points]
origin_ratio_x = 0.525
origin_ratio_y = 0.64
def generate_cup_pattern_svg(
pattern_points: List[PatternPoint],
file_name: str,
width: float,
height: float,
):
# Create the SVG drawing
dwg = svgwrite.Drawing(
file_name,
profile='tiny',
size=(f'{width}mm', f'{height}mm'),
viewBox=f"0 0 {width} {height}",
)
# Move to the first point
start_point = pattern_points[0].origin
path_data = f'M {start_point[0]},{start_point[1]} '
# Iterate through the points and create path data
n = len(pattern_points)
for i in range(n):
current = pattern_points[i]
next_point = pattern_points[(i + 1) % n]
if current.control_cw and next_point.control_ccw:
# Cubic Bezier curve
path_data += f'C {current.control_cw[0]},{current.control_cw[1]} '
path_data += f'{next_point.control_ccw[0]},{next_point.control_ccw[1]} '
path_data += f'{next_point.origin[0]},{next_point.origin[1]} '
else:
# Line to the next point
path_data += f'L {next_point.origin[0]},{next_point.origin[1]} '
# Close the path
path_data += 'Z'
# Add the path to the drawing inside a <g> element with translation
g = dwg.g(transform=f'translate({origin_ratio_x * width},{origin_ratio_y * height})')
g.add(dwg.path(d=path_data, fill='none', stroke='black'))
dwg.add(g)
# Save the SVG file
dwg.save()
base_width = 200
base_height = 175
# Create output directories if they don't exist
os.makedirs('_site/assets', exist_ok=True)
# Generate SVG files for each cup size
for cup_size in cup_sizes:
scale_factor = cup_size.scale_factor()
scaled_points = scale_pattern_points(pattern_points, scale_factor)
file_name = f'_site/assets/cup_size_{cup_size.size_no}.svg'
generate_cup_pattern_svg(
scaled_points,
file_name,
width=base_width * scale_factor,
height=base_height * scale_factor,
)
# Generate the index.html file
env = Environment(loader=FileSystemLoader('.'))
template = env.get_template('template.html')
html_content = template.render(cup_sizes=cup_sizes)
with open('_site/index.html', 'w') as f:
f.write(html_content)
print("Website generated successfully in the '_site' directory.")