2024-03-29 14:37:39 发布
网友
有没有一种方法可以组合各种内置的动画功能,甚至创建自定义功能? 我喜欢以下功能:
输入输出三次方、输入输出四次方、输入输出正弦
但我想做一些像:
输入/输出正弦
看看会不会没事。你知道吗
用其他数学函数来创建各种效果也很有趣。你知道吗
如何在Kivy做到这一点?你知道吗
你所指出的可能有几种解释,所以我将向你展示不同的可能性:
使用从p1到p2的in_cubic动画和从p2到终点p3的out_sine动画。你知道吗
in_cubic
out_sine
from kivy.animation import Animation from kivy.app import App from kivy.uix.button import Button class TestApp(App): def animate(self, instance): animation = Animation(pos=(200, 200), t='in_cubic') animation += Animation(pos=(400, 400), t='out_sine') animation.start(instance) def build(self): button = Button(size_hint=(None, None), text='plop', on_press=self.animate) return button if __name__ == '__main__': TestApp().run()
应用50%的进位立方和进位立方,为此我们创建了一个新函数:
from kivy.animation import Animation, AnimationTransition from kivy.app import App from kivy.uix.button import Button def in_cubic_out_sine(progress): return AnimationTransition.in_cubic(progress) if progress < 0.5 else AnimationTransition.out_sine(progress) class TestApp(App): def animate(self, instance): animation = Animation(pos=(200, 200), t=in_cubic_out_sine) animation.start(instance) def build(self): button = Button(size_hint=(None, None), text='plop', on_press=self.animate) return button if __name__ == '__main__': TestApp().run()
一般来说,您可以实现自己的函数,唯一需要记住的是,progress取0到1之间的值:
from kivy.animation import Animation from kivy.app import App from kivy.uix.button import Button from math import cos, sin, pi, exp def custom_animation(progress): return 1 - exp(-progress**2)*cos(progress*pi)**3 class TestApp(App): def animate(self, instance): animation = Animation(pos=(200, 200), t=custom_animation) animation.start(instance) def build(self): button = Button(size_hint=(None, None), text='plop', on_press=self.animate) return button if __name__ == '__main__': TestApp().run()
你所指出的可能有几种解释,所以我将向你展示不同的可能性:
使用从p1到p2的
in_cubic
动画和从p2到终点p3的out_sine
动画。你知道吗应用50%的进位立方和进位立方,为此我们创建了一个新函数:
一般来说,您可以实现自己的函数,唯一需要记住的是,progress取0到1之间的值:
相关问题 更多 >
编程相关推荐