Skip to content

Transform after creation? #120

Answered by cduck
tilmanb asked this question in Q&A
Discussion options

You must be logged in to vote

Your code is very close to working. What you want is the Use element which draws a duplicate of the given shape at a specific x, y offset: d.append(draw.Use(my_shape, x_offset, y_offset))

import drawsvg as draw

d = draw.Drawing(100, 100, origin='center')
g = (-5, -5, 5, 5)

rect_raw = draw.Rectangle(g[0], g[1], g[2], g[3],
                          stroke='black', fill='none', stroke_width=2)

positions = (
    (16, 9),
    (84, 9),
    (49, 16),
    (23, 37),
    # more positions...
)
for x, y in positions:
    x = x - 50
    y = y - 50

    d.append(draw.Use(rect_raw, x, y))  # <-- This line

d


To explain why your code didn't work, rect_raw.transform is not where the SVG attribute is…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by cduck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants