Created
October 11, 2019 10:46
-
-
Save me2beats/6771f8f022853a8793e4bfa93fff2120 to your computer and use it in GitHub Desktop.
Kivy image transition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.lang import Builder | |
KV = """ | |
FloatLayout | |
MyWidget | |
source1:'1.jpg' | |
source2:'cosmos.webp' | |
<MyWidget> | |
left:False | |
source1:None | |
source2:None | |
split_x: 0 | |
on_touch_down: self.test() | |
canvas.before: | |
Rectangle: | |
size: self.size | |
pos: self.pos | |
source:root.source2 | |
StencilPush | |
PushMatrix | |
Rectangle: | |
size: root.split_x, self.height | |
pos: self.pos | |
PopMatrix | |
StencilUse | |
canvas: | |
Rectangle: | |
pos: self.pos | |
size: self.size | |
source: root.source1 | |
canvas.after: | |
StencilUnUse | |
StencilPop | |
""" | |
from kivy.animation import Animation as A | |
from kivy.uix.widget import Widget | |
def custom_anim(x): | |
return x**((1 - x)*2) | |
class MyWidget(Widget): | |
def test(self, *_): | |
new_split_x= 0 if self.left else self.width | |
a = A(split_x = new_split_x, t=custom_anim, d= 0.5) | |
#a = A(split_x = new_split_x, t='in_out_sine', d= 0.5) | |
self.left = not self.left | |
a.start(self) | |
class MyApp(App): | |
def build(self): | |
return Builder.load_string(KV) | |
MyApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to make it work, pls specify your images (source1, source2) names.
demo https://imgur.com/a/lZI3CsR