0

我正在尝试使用 python svgwrite 使对象同时缩放和旋转。到目前为止,我的努力是添加两个连续的“animateTransform”。然而,它似乎只考虑了最后一个动作,如我的示例所示。

import svgwrite 

path = [(100,100),(100,200),(200,200),(200,100)]

image = svgwrite.Drawing('test.svg',size=(300,300))

rectangle = image.add(image.polygon(path,id ='polygon',stroke="black",fill="white"))
rectangle.add(image.animateTransform("rotate","transform",id="polygon", from_="0 150 150", to="360 150 150",dur="4s",begin="0s",repeatCount="indefinite"))
rectangle.add(image.animateTransform("scale","transform",id="polygon", from_="0", to="1",dur="4s",begin="0s",repeatCount="indefinite"))

image.save()
display(SVG('test.svg'))

任何人都可以帮忙吗?

4

1 回答 1

0

这可能来得太晚了,但对我有用的是添加additive = "sum"到两个动画中。请注意,添加动画的顺序会影响最终结果。

import svgwrite 

path = [(100,100),(100,200),(200,200),(200,100)]

image = svgwrite.Drawing('test.svg',size=(300,300))

rectangle = image.add(image.polygon(path,id ='polygon',stroke="black",fill="white"))
rectangle.add(image.animateTransform("scale","transform",id="polygon", from_="0", to="1",dur="4s",begin="0s",repeatCount="indefinite", additive = "sum"))    
rectangle.add(image.animateTransform("rotate","transform",id="polygon", from_="0 150 150", to="360 150 150",dur="4s",begin="0s", additive = "sum", repeatCount="indefinite"))

image.save()
display(SVG('test.svg'))
于 2021-03-23T15:53:30.703 回答