# Purpose: draw a maurer rose with polylines
# https://en.wikipedia.org/wiki/Maurer_rose
# Created: 13.10.2019
# Copyright (c) 2019, Manfred Moitzi
# License: MIT License
from typing import Iterable, Tuple
import math
import ezdxf

N = 6  # The rose has n petals if N is odd, and 2N petals if N is even.
D = 71  # delta angle in degrees
TWO_PI = math.pi * 2
STEP360 = TWO_PI / 360


def maurer_rose(n: int, d: int, radius: float) -> Iterable[Tuple[float, float]]:
    i = 0
    while i < TWO_PI:
        k = i * d
        r = radius * math.sin(n * k)
        x = r * math.cos(k)
        y = r * math.sin(k)
        yield x, y
        i += STEP360


def main(filename: str, n: int, d: int) -> None:
    doc = ezdxf.new()
    msp = doc.modelspace()
    msp.add_lwpolyline(maurer_rose(n, d, 250), dxfattribs={'closed': True})
    doc.saveas(filename)


if __name__ == '__main__':
    main('maurer_rose.dxf', N, D)

@@ -638,24 +638,272 @@
 = STEP360%0A%0A%0A
+def maurer_rose_outline(n: int, radius: float) -%3E Iterable%5BTuple%5Bfloat, float%5D%5D:%0A    i = 0%0A    while i %3C TWO_PI:%0A        r = radius * math.sin(n * i)%0A        x = r * math.cos(i)%0A        y = r * math.sin(i)%0A        yield x, y%0A        i += STEP360%0A%0A%0A
 def main(fil
@@ -988,16 +988,109 @@
 space()%0A
+    msp.add_lwpolyline(maurer_rose_outline(n, 250), dxfattribs=%7B'closed': True, 'color': 1%7D)%0A
     msp.
@@ -1154,16 +1154,28 @@
 d': True
+, 'color': 5
 %7D)%0A    d

add petal outline for example maurer rose