0

I want to transform a gradient to a certain degree.

# I want to do something like this

transform = svgwrite.mixins.Transform()
transform = transform.rotate(angle="138")
vert_grad = svgwrite.gradients.LinearGradient(start=(0, 0), end=(0,1), id="vert_lin_grad")
vert_grad.add_stop_color(offset='0%', color='blue', opacity=None)
vert_grad.add_stop_color(offset='50%', color='green', opacity=None)
vert_grad.add_stop_color(offset='100%', color='yellow', opacity=None)
dwg.defs.add(vert_grad)

The documentation tells me to use the Transform mixin: https://svgwrite.readthedocs.io/en/latest/classes/gradients.html#svg-attributes

But I'm not familiar with using mixins in python, and the above code gives me this error:

'Transform' object has no attribute 'attribs'

I have also been unable to find examples with SVG transform.

How do I use the Transform mixin?

kyuden
  • 197
  • 1
  • 11

1 Answers1

0

got it after reading this article: https://www.pythontutorial.net/python-oop/python-mixin/

vert_grad = svgwrite.gradients.LinearGradient(start=(0, 0), end=(0,1), id="vert_lin_grad")
vert_grad.add_stop_color(offset='0%', color='blue', opacity=None)
vert_grad.add_stop_color(offset='50%', color='green', opacity=None)
vert_grad.add_stop_color(offset='100%', color='yellow', opacity=None)

# add this line
vert_grad.rotate("45")
dwg.defs.add(vert_grad)
kyuden
  • 197
  • 1
  • 11