更新:与其他人讨论后,我认为这是一个有点愚蠢的问题。我想用改变的宽度制作贝塞尔曲线的动画,但它没有宽度属性。使用 Line Bezier,我可以更改宽度,但无法制作动画。
我无法像 Line
那样更改 Bezier
曲线的 witdh
。
这是代码:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import *
class MyLayout(Widget):
def __init__(self):
super(MyLayout, self).__init__()
with self.canvas:
self.L=Bezier(points=[200,450,500,300,600,150],width=12)
self.k=Line (bezier=[100,350,400,200,500,50 ],width=12)
class MyApp(App):
def __init__(self):
super(MyApp, self).__init__()
def build(self):
return MyLayout()
if __name__=="__main__":
MyApp().run()
问题是,
上面的曲线不是width=12
。
我认为这是因为 Kivy 的 Bezier 类没有属性 width
因为当我在 kv
lang 上执行此操作时,它会给我 AttributeError: 'kivy.graphics. vertex_instructions.Bezier' 对象没有属性 'width'
。那么,为什么不将 Line
与 bezier
一起使用呢?我想在其上使用 Animation
,当我尝试在 Line
上使用 bezier
时,我得到 AttributeError: attribute 'bezier' of “kivy.graphics.vertex_instructions.Line”对象不可读
。
所以问题,
如何更改贝塞尔曲线的宽度
。如果不可能,有没有办法找到给定x的cruve(或ys)的y,以便我可以在这些点上放置椭圆并调整它们的大小以模拟宽度?
谢谢,请原谅我的英语♥
最佳答案
该行可以使用bezier:
,例如:
Line:
bezier:[n1,n2,n3,n4]
width:3
这是一个Line
,不是Bezier
,但你得到相同的结果...
一个例子:
from kivy.app import App
from kivy.lang.builder import Builder
from kivy.uix.boxlayout import BoxLayout
posicao=[]
class Draw(BoxLayout):
def __init__(self, **kwargs):
super(Draw, self).__init__(**kwargs)
def on_touch_down(self,touch):
posicao.append(touch.pos)
def on_touch_up(self,touch):
posicao.clear()
def on_touch_move(self,touch):
Line = Builder.load_string(
"""
FloatLayout:
canvas:
Color:
rgba:11,.1,1,1
Line:
points: {pos}
width:14
""".format(pos=(touch.pos, posicao[0])))
self.add_widget(Line)
posicao.clear()
posicao.append(touch.pos)
class Code(App):
def build(self):
return Draw()
if __name__ == '__main__':
Code().run()
或者:
from kivy.app import App
from kivy.lang.builder import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.graphics import *
posi = []
Builder.load_string(
"""
<Draw>:
""")
class Draw(BoxLayout):
def __init__(self, **kwargs):
super(Draw, self).__init__(**kwargs)
def on_touch_down(self,touch):
posi.clear()
posi.append(touch.pos)
def on_touch_up(self,touch):
posi.clear()
def on_touch_move(self,touch):
with self.canvas:
Line(points=[posi[0], touch.pos],width=14)
posi.clear()
posi.append(touch.pos)
class Code(App):
def build(self):
return Draw()
if __name__ == '__main__':
Code().run()
关于python - 具有自定义宽度的动画 Kivy Bezier 曲线? (有点傻的问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66729316/