簡體   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