1 Star 0 Fork 0

KojimaNotGood/PythonVideoPulserateV2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
hbsanim.py 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
Leeuwen, M.C. van 提交于 2020-05-17 13:57 . new anim
import xml.etree.ElementTree as ET
tree = ET.parse('hbsDrawing.svg')
root = tree.getroot()
#%%
#%%
f = open("hbsDrawing.svg",'r')
text = f.read()
f.close()
ids = ["path3061-0-4"]
tag = ids[0]
regex = f"({tag})([^/]*)(/>)"
p = re.compile(regex)
result = p.search(text)
backslash_idx = result.span()[1]-2
anim = '\n<animate attributeName="stroke-opacity" values="0.5;0.5;1;0.5;0.5" dur="5s" repeatCount="indefinite" />'
ender = '\n</path>'
#%% find layer, make mask with id
layer = "layer4"
position = text.find(f'id="{layer}"')
group_openers = text.("<g")
group_closers = text.find("/g>")
distances = [openpos - position for openpos in group_openers if openpos - position > 0]
#%%
newtext = text[:backslash_idx] + " >" + anim + ender + text[backslash_idx+2:]
f = open("hbsAnim.svg","w")
f.write(newtext)
f.close()
#%%
from xml.dom import minidom
doc = minidom.parse("hbsDrawing.svg") # parseString also exists
path_strings = [path.getAttribute('id') for path
in doc.getElementsByTagName('g')]
doc.unlink()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/noooToday/PythonVideoPulserateV2.git
[email protected]:noooToday/PythonVideoPulserateV2.git
noooToday
PythonVideoPulserateV2
PythonVideoPulserateV2
master

搜索帮助