-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
28 lines (24 loc) · 874 Bytes
/
model.py
File metadata and controls
28 lines (24 loc) · 874 Bytes
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
import sys
from typing import Literal
from muscad import Cube, Cylinder, Union
from util import InvalidParameterException
if sys.platform == 'emscripten':
# direct import is not possible, since we need to download the files manually
includes = {
"internal": "./internal.py",
}
else:
import internal
def generate(length: float, count: int, mode: Literal["centered", "offset"]) -> list[tuple[str, str]]:
size = internal.size
if count < 1:
raise InvalidParameterException(["count"], "count must be at least 1")
c1 = Cube(length, size, size)
c2 = Union(*[Cylinder(h=length, d=size).y_rotate(90.0).align(center_y=i) for i in range(count)])
if mode == "offset":
c1 = c1.align(left=size)
c2 = c2.align(left=size)
return [
("cube", str(c1)),
("cylinder", str(c2))
]