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

2024-10-05 10:49:10 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我需要一些关于使用animate模块的帮助,(比如animateColor,animateMotion…),因为即使我阅读了文档,也阅读了svgwrite包中的所有示例,我也无法找到一种方法来获得关于如何正确使用它的一些信息。在

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

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

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


Tags: 模块the信息linepositionstartenddraw
1条回答
网友
1楼 · 发布于 2024-10-05 10:49:10

下面是一个旋转矩形和颜色更改文本的示例

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并非在所有浏览器中都能工作

相关问题 更多 >

    热门问题