Rounded Rectangle



  • Snippet do draw rectangle with rounded corner:

    def rectRounded(x,y,w,h,radius):
        path = BezierPath()
        sR=0.5*radius
        w=w-radius
        h=h-radius
        path.rect(x,y+sR,w+radius,h)
        path.rect(x+sR,y,w,h+radius)
        path.oval(x,y,radius,radius)
        path.oval(x+w,y,radius,radius)
        path.oval(x,y+h,radius,radius)
        path.oval(x+w,y+h,radius,radius)
        path.removeOverlap()
        drawPath(path)
    

    It is possible to manually add it in drawBot module ?


  • admin

    cool way to make a rounded rect!

    there are already a roundedRect example in the repository: see https://github.com/typemytype/drawbot/blob/master/examples/roundedRect.py

    I would encourage you to make a python package out of your helper tools that you import when you needed it...

    # a separate file with the name "roundedRect.py"
    def roundedRect(...):
        # draw your stuff here
    
    # an other file in the same directory
    
    #  name of the file/module  name of the function 
    from roundedRect import roundedRect
    
    # call it
    roundedRect(...)
    

    hope this makes sense!


Log in to reply