Why would I declare a newPath() as opposed to defining a BezierPath() with a variable name?



  • Just a matter of convenience, if I'm only using one path?


  • admin

    In some cases it's a lot easier to have an object of path to work with, instead of the combo: newPath(), moveTo(..), lineTo(..), curveTo(..), closePath()

    stroke(0)
    fill(None)
    # create a new path object
    path = BezierPath()
    # add a move to to the path object
    path.moveTo((200, 200))
    # add a line to to the path object
    path.lineTo((200, 100))
    
    # this creates a new path and set it as current path in the stack
    newPath()
    # add a move to to the current path
    moveTo((100, 100))
    # add a line to to the current path 
    lineTo((100, 200))
    # draw the current path
    drawPath()
    
    # draw the path, instead of the current one
    drawPath(path)
    


  • That's what I suspected. It seemed like the kind of question students would ask and I wanted to make sure the answer I gave was the right one. Thanks, Frederik.


Log in to reply