python - 如何在Python中使用 "svgwrite"库创建动画

标签 python animation svg

我正在使用 SVGWRITE 库创建生物信息学工具。

我需要一些使用 animate 模块的帮助(例如 animateColor、animateMotion...),因为即使我阅读了文档,也阅读了 svgwrite 包中的所有示例,我找不到方法了解有关如何正确使用它的一些信息。

我正在创建的 SVG 绘图仅由矩形组成,我称之为外显子,这就是我创建它们的方式:

def drawExon(dwg,lineNumber,start,end,rvb):

""" 
A function which draw a new exon on a opened dwg draw 
it draw that exon from 'start', to 'end' (x position)
at the line 'lineNumber' (y position) with the color'rvb' 
"""

  dwg.add(dwg.rect((start,lineNumber*line_height),(end - start, 
  exon_height),fill=svgwrite.rgb(rvb[0],rvb[1],rvb[2])))

我想添加这些矩形的动画,当我飞过矩形时,我希望在该矩形上显示一个 ID(在其上方的文本框中),并且该矩形可以改变颜色。

问题是我不知道如何以及在哪里应用 animate 模块,也不知道我必须给出什么样的参数......

好吧,我在过去的两个小时内尝试做这样的事情,我在以下链接上阅读了很多内容: http://svgwrite.readthedocs.org/en/latest/classes/animate.html#animate

但这并没有帮助我找到答案。

最佳答案

这是旋转矩形和更改文本颜色的示例

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"))
text = image.add(image.text('rectangle1',insert=(150,30),id="text"))
text.add(image.animateColor("fill", attributeType="XML",from_="green", to="red",id="text", dur="4s",repeatCount="indefinite"))

image.save()

请注意,animateColor 并不适用于所有浏览器

关于python - 如何在Python中使用 "svgwrite"库创建动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30799221/

相关文章:

python - 从 Mayavi 中的剖切面检索线

python - 如何从 Python 中的被调用模块访问调用模块命名空间?

c - 如何在 OpenVG 上下文中导入 SVG?

javascript - D3 sunburst 图 : Setting arc. cornerRadius() causes invalid path with arcTween

ios - iOS 中 UIImageView 的更快替代品

javascript - 单击鼠标时 D3 将值更新为新数据集

python - 如何使用 Windows 操作系统从 .pkl 文件获取数据

python - 针对特定列的逐行填充?

Android:ImageView 上的矩阵运算,动画?

javascript - jQuery 动画延迟