显示正在制作 kivy 的线
show the Line being made kivy
是否可以显示正在绘制的线而不是立即出现的线。我尝试制作多个加载栏并旋转,但认为制作线条会更简单一些。
我有我想要遵循的轮廓,每个直角都是自己画的线。 On_pre_enter 我的出线已经给出,on_enter 红线已经画好了,但我希望在给定时间内进入时画出红线。我在 with self.canvas.before:
之后添加了 amin
行,但屏幕是动画的而不是行。
mazeupdate.py
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.clock import Clock
from kivy.properties import NumericProperty
from kivy.uix.progressbar import ProgressBar
from kivy.config import Config
from kivy.graphics import Line, Color, Rectangle
from kivy.animation import Animation
class results(Screen):
def on_pre_enter(self):
with self.canvas.before:
Color(1,1,1)
Line(points=[100, 100, 100, 200, 200, 200, 200, 100, 300, 100, 300, 200], width=3)
def on_enter(self):
with self.canvas.before:
Color(1,0,0)
Line(points=[100, 100, 100, 200], width=5)
anim = Animation(pos=(80, 10))
anim &= Animation(size=(800, 800), duration=5)
anim.start(self)
class mazeupdateApp(App):
Config.set('graphics', 'width', '800')
Config.set('graphics', 'height', '600')
def build(self):
FadeTransition.clearcolor = (1,1,1,1)
sm = ScreenManager(transition=FadeTransition())
sm.add_widget(results(name='one'))
return sm
if __name__ == '__main__':
mazeupdateApp().run()
您可以为线条的终点设置动画,然后在每次更改终点时重新绘制线条:
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.properties import ListProperty
from kivy.config import Config
from kivy.graphics import Line, Color
from kivy.animation import Animation
class results(Screen):
anim_pt = ListProperty([]) # this is the line endpoint
def on_pre_enter(self):
with self.canvas.before:
Color(1,1,1)
Line(points=[100, 100, 100, 200, 200, 200, 200, 100, 300, 100, 300, 200], width=3)
def on_enter(self):
# start the red line with no points
with self.canvas.before:
Color(1,0,0)
self.line = Line(width=5) # saves a reference to the line
# animate the end point (self.anim_pt)
self.anim_pt = [100, 100]
anim = Animation(anim_pt=[100, 200], d=3)
anim.start(self)
def on_anim_pt(self, widget, progress):
# called when anim_pt changes
# set up the line points
points = [100, 100]
points.extend(self.anim_pt)
# remove the old line
self.canvas.before.remove(self.line)
# draw the updated line
with self.canvas.before:
self.line = Line(points=points, width=5)
class mazeupdateApp(App):
Config.set('graphics', 'width', '800')
Config.set('graphics', 'height', '600')
def build(self):
FadeTransition.clearcolor = (1,1,1,1)
sm = ScreenManager(transition=FadeTransition())
sm.add_widget(results(name='one'))
return sm
if __name__ == '__main__':
mazeupdateApp().run()
是否可以显示正在绘制的线而不是立即出现的线。我尝试制作多个加载栏并旋转,但认为制作线条会更简单一些。
我有我想要遵循的轮廓,每个直角都是自己画的线。 On_pre_enter 我的出线已经给出,on_enter 红线已经画好了,但我希望在给定时间内进入时画出红线。我在 with self.canvas.before:
之后添加了 amin
行,但屏幕是动画的而不是行。
mazeupdate.py
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.clock import Clock
from kivy.properties import NumericProperty
from kivy.uix.progressbar import ProgressBar
from kivy.config import Config
from kivy.graphics import Line, Color, Rectangle
from kivy.animation import Animation
class results(Screen):
def on_pre_enter(self):
with self.canvas.before:
Color(1,1,1)
Line(points=[100, 100, 100, 200, 200, 200, 200, 100, 300, 100, 300, 200], width=3)
def on_enter(self):
with self.canvas.before:
Color(1,0,0)
Line(points=[100, 100, 100, 200], width=5)
anim = Animation(pos=(80, 10))
anim &= Animation(size=(800, 800), duration=5)
anim.start(self)
class mazeupdateApp(App):
Config.set('graphics', 'width', '800')
Config.set('graphics', 'height', '600')
def build(self):
FadeTransition.clearcolor = (1,1,1,1)
sm = ScreenManager(transition=FadeTransition())
sm.add_widget(results(name='one'))
return sm
if __name__ == '__main__':
mazeupdateApp().run()
您可以为线条的终点设置动画,然后在每次更改终点时重新绘制线条:
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.properties import ListProperty
from kivy.config import Config
from kivy.graphics import Line, Color
from kivy.animation import Animation
class results(Screen):
anim_pt = ListProperty([]) # this is the line endpoint
def on_pre_enter(self):
with self.canvas.before:
Color(1,1,1)
Line(points=[100, 100, 100, 200, 200, 200, 200, 100, 300, 100, 300, 200], width=3)
def on_enter(self):
# start the red line with no points
with self.canvas.before:
Color(1,0,0)
self.line = Line(width=5) # saves a reference to the line
# animate the end point (self.anim_pt)
self.anim_pt = [100, 100]
anim = Animation(anim_pt=[100, 200], d=3)
anim.start(self)
def on_anim_pt(self, widget, progress):
# called when anim_pt changes
# set up the line points
points = [100, 100]
points.extend(self.anim_pt)
# remove the old line
self.canvas.before.remove(self.line)
# draw the updated line
with self.canvas.before:
self.line = Line(points=points, width=5)
class mazeupdateApp(App):
Config.set('graphics', 'width', '800')
Config.set('graphics', 'height', '600')
def build(self):
FadeTransition.clearcolor = (1,1,1,1)
sm = ScreenManager(transition=FadeTransition())
sm.add_widget(results(name='one'))
return sm
if __name__ == '__main__':
mazeupdateApp().run()