Grouping paths/elements



  • Is it useful to allow the grouping of elements like text/paths/…? That way, several elements on the canvas can be moved/scaled/rotated at the same time and around the came coördinates, without having to code all of them one by one.


  • admin

    I would like to encourage you to write your own 'grouped' items!

    make function, a def myTextRect(...), that draws anything you like to draw!!!

    like:

    def myTextRect(txt, box, border):
        x, y, w, h = box
        with savedState():
            
            with savedState():
                stroke(0, 1, 1)
                fill(None)
                strokeWidth(border)
                rect(x - border, y - border, w + border * 2, h + border * 2)
                
                corners = [
                    (x - border, y - border),
                    (x + w + border, y - border),
                    (x + w + border, y + h + border),
                    (x - border, y + h + border),
                ]
                stroke(None)
                fill(1, 0, 0)
                dotSize = border * 2
                for cornerX, cornerY in corners:
                    oval(cornerX - dotSize, cornerY - dotSize, dotSize * 2, dotSize * 2)
            
            font("Times-Italic")
            fontSize(20)
            fill(0, 1, 0)
            textBox(txt, box)
            
    
    translate(100, 100)
    myTextRect("hello world" * 100, (20, 20, 300, 200), 20)
    translate(0, 400)
    myTextRect("foo bar" * 100, (20, 20, 300, 200), 20)
    


  • @frederik Got it. Thanks! 🙂