gpt4 book ai didi

canvas - Kivy 中的脉动背景颜色

转载 作者:行者123 更新时间:2023-12-05 03:02:40 26 4
gpt4 key购买 nike

我是 kivy 的新手,但我真的坚持这一点。有什么方法可以在 Canvas 上产生类似于 CSS 中这种效果的脉冲背景:

https://codepen.io/LukeAskew/pen/gabgom

body {
background-color: #222;
animation-name: color;
animation-duration: 2s;
animation-iteration-count: infinite;
}

@keyframes color {
0% {
background-color: #222;
}
50% {
background-color: #4285f4;
}
100 {
background-color: #222;
}
}

是否可以使用 kivy 做这样的事情?

最佳答案

您可以使用 kivy.Animation 来设置背景颜色的动画:

from kivy.animation import Animation
from kivy.app import App
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.properties import ObjectProperty
from kivy.uix.widget import Widget


class Pulser(Widget):
bg_color = ObjectProperty([1, 1, 1, 1])

def __init__(self, **kwargs):
super(Pulser, self).__init__(**kwargs)
Clock.schedule_once(self.start_pulsing, 2)

def start_pulsing(self, *args):
anim = Animation(bg_color=[1,0,0,1]) + Animation(bg_color=[1,1,1,1])
anim.repeat = True
anim.start(self)


theRoot = Builder.load_string('''
Pulser:
canvas:
Color:
rgba: self.bg_color
Rectangle:
pos: self.pos
size: self.size

''')

class PulserApp(App):
def build(self):
return theRoot

if __name__ == "__main__":
PulserApp().run()

关于canvas - Kivy 中的脉动背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54598379/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com