python - 用自定义宽度动画 Kivy Bezier 曲线?(有点傻的问题)
问题描述
解决方案
The Bezier
has no width
property, but the Line
does. So you can animate that width
. An easy way to do that is by animating a NumericProperty
that holds the width. Here is a modified version of your code that does that:
from kivy.animation import Animation
from kivy.app import App
from kivy.clock import Clock
from kivy.properties import NumericProperty
from kivy.uix.widget import Widget
from kivy.graphics import *
class MyLayout(Widget):
line_width = NumericProperty(12)
def __init__(self):
super(MyLayout, self).__init__()
with self.canvas:
self.L=Bezier(points=[200,450,500,300,600,150],width=self.line_width)
self.k=Line (bezier=[100,350,400,200,500,50 ],width=self.line_width)
def on_line_width(self, instance, new_width):
self.k.width = new_width
class MyApp(App):
def build(self):
Clock.schedule_once(self.anim)
return MyLayout()
def anim(self, dt):
a = Animation(line_width=3)
a.start(self.root)
if __name__=="__main__":
MyApp().run()
If you build the Line
in kv
, then you don't even need the on_line_width()
method since kivy will do the binding for you.
推荐阅读
- python - 数学函数查找范围内数字的最大倍数
- database - Sqlite数据库+统一
- angular - 我得到的只是关键而不是 AngularFire2 的价值:Realtime Database version 5 using Angular 6.0
- javascript - Javascript - 修改数组值
- jquery - 获取表格单元格内的文本高度
- azure - 看不到我在 Azure 门户上创建的警报
- artifactory - 神器是否支持访问令牌交换?
- angular - Angular 5:在点击事件上检测firestore文档ID
- python - 在 numpy.where 返回的数组之间查找唯一索引
- ruby-on-rails - 我无法对远程主机运行“cap XXX deploy”