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
|
# Copyright (c) 2022, Manfred Moitzi
# License: MIT License
from pathlib import Path
import ezdxf
from ezdxf import path, zoom
from ezdxf.math import Matrix44
CWD = Path("~/Desktop/Outbox").expanduser()
if not CWD.exists():
CWD = Path(".")
# ------------------------------------------------------------------------------
# This example shows how triangulate arbitrary path objects, a doughnut in this
# special case.
#
# docs: https://ezdxf.mozman.at/docs/path.html#ezdxf.path.triangulate
# ------------------------------------------------------------------------------
def main():
doc = ezdxf.new()
msp = doc.modelspace()
circle0 = path.unit_circle(segments=8)
circle1 = circle0.transform(Matrix44.scale(3))
colors = [1, 2, 3, 4, 5, 6, 7]
count = len(colors)
for index, points in enumerate(path.triangulate([circle1, circle0])):
msp.add_solid(points, dxfattribs={"color": colors[index % count]})
zoom.extents(msp)
doc.saveas(CWD / "triangulated_doughnut.dxf")
if __name__ == "__main__":
main()
|