繁体   English   中英

如何在python中使用“ svgwrite”库创建动画

[英]How to create an animation with the “svgwrite” library in python

我正在使用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出现在该矩形上(在其上方的文本框中),并且该矩形可以更改颜色。

问题是我不知道如何以及在何处应用动画模块,也不知道必须提供哪种参数。

好吧,我在最近两个小时内尝试执行此操作,并在以下链接上阅读了很多内容: 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不能在所有浏览器中使用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM