Even-Odd Fill Rule



  • Subject: Help Needed with Even-Odd Fill Rule for Maurer Rose Animation

    Hello DrawBot Community,

    Me and my imaginary friend (AI) are reaching out for human intellignce once again. 😉 I'm currently working on creating an animated Moire Effect based on a Maurer Rose using DrawBot and have encountered an issue with applying the even-odd fill rule. The animation is supposed to alternate fills correctly to mimic the visual effect seen in examples like the one on this website. https://www.sqrt.ch/Buch/Maurer/maurerrosesanim.html However, doe to the missing even-odd filling rule, we haven't been able to achieve the desired effect.

    Here's what I’ve tried so far:

    Initial Attempt Without Even-Odd Fill Rule: (be carefull running this script, it takes ages to render. reduce the z variable to a low prime number)

    # Parameters for the Maurer Rose
    n = 5
    d = 1
    z = 853
    ms = 90
    dStroke = 1
    dFarbe = (0, 0, 1)  # Blue stroke color
    cFarbe = (1, 0, 0)  # Red fill color 
    
    newDrawing()
    
    for frame in range(z):
        newPage(1010, 1010)
        frameDuration(ms / 1000)
        translate(width() / 2, height() / 2)
    
        fill(0)
        rect(-width() / 2, -height() / 2, width(), height())
    
        path = BezierPath()
        for theta in range(z + 1):
            k = (theta * d * 2 * pi) / z
            r = -500 * sin(n * k)
            x = r * cos(k)
            y = r * sin(k)
            if theta == 0:
                path.moveTo((x, y))
            else:
                path.lineTo((x, y))
    
        path.closePath()
    
        fill(*cFarbe)
        drawPath(path)
    
        stroke(*dFarbe)
        strokeWidth(dStroke)
        lineJoin('round')
        drawPath(path)
    
        d += 1
    
    saveImage("maurer_rose_animation.gif")
    endDrawing()
    
    

    Attempt Without Unsupported Methods:

    # Draw the fill and stroke
    def draw_maurer_rose(d, n, z, dStroke, dFarbe, cFarbe):
        path = BezierPath()
        for theta in range(z + 1):
            k = (theta * d * 2 * pi) / z
            r = -500 * sin(n * k)
            x = r * cos(k)
            y = r * sin(k)
            if theta == 0:
                path.moveTo((x, y))
            else:
                path.lineTo((x, y))
        path.closePath()
    
        fill(*cFarbe)
        drawPath(path)
    
        stroke(*dFarbe)
        strokeWidth(dStroke)
        lineJoin('round')
        drawPath(path)
    
    # Animation loop
    for frame in range(z):
        newPage(1010, 1010)
        frameDuration(ms / 1000)
        translate(width() / 2, height() / 2)
    
        fill(1)
        rect(-width() / 2, -height() / 2, width(), height())
    
        draw_maurer_rose(d, n, z, dStroke, dFarbe, cFarbe)
    
        d += 1
    
    saveImage("maurer_rose_animation.gif")
    endDrawing()
    
    

    ...despite several attempts, I haven't been able to achieve the desired even-odd fill rule effect. I would appreciate any guidance or suggestions on how to properly implement the even-odd fill rule for this animation in DrawBot.

    Thank you in advance for your help!



  • Maybe this post can help you on your way?



  • Hey @monomonnik
    The problem is, that the rose is made of a single path and not two overlapping objects. I hoped there is some kind of a blend mode to clear overlapping colors.



  • You are correct, I should have looked better.

    I don’t know if there exist these kind of filters for DrawBot (I assume you mean something like Illustrator’s Pathfinder tool).

    I did some reading on the underlying NSBezierPath, which has an even-odd winding rule, but I'm not smart enough to figure out if that's useable, let alone how.


Log in to reply