[英]svgwrite: how to use Transform mixin
我想將漸變轉換到一定程度。
# 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)
文檔告訴我使用Transform mixin: https://svgwrite.readthedocs.io/en/latest/classes/gradients.html#svg-attributes
但是我不熟悉在 python 中使用 mixins,上面的代碼給了我這個錯誤:
'Transform' object has no attribute 'attribs'
我也找不到 SVG 變換的例子。
如何使用 Transform mixin?
看完這篇文章就知道了: 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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.