Skip to content

Instantly share code, notes, and snippets.

@inclement
Created March 23, 2014 13:10
Show Gist options
  • Select an option

  • Save inclement/9722880 to your computer and use it in GitHub Desktop.

Select an option

Save inclement/9722880 to your computer and use it in GitHub Desktop.
import kivy
from kivy.app import App
from kivy.clock import Clock
from kivy.graphics import Rectangle, Ellipse
from kivy.uix.widget import Widget
from kivy.graphics.fbo import Fbo
from kivy.utils import get_random_color
from kivy.animation import Animation
from kivy.core.image import Image
from kivy.graphics import Color
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.relativelayout import RelativeLayout
from kivy.uix.label import Label
#from kivy.properties import ObjectProperty
from kivy.lang import Builder
from kivy.graphics.opengl import glBlendFunc, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
from kivy.config import Config
Config.set('graphics', 'width', '720')
Config.set('graphics', 'height', '720')
from kivy.base import EventLoop
EventLoop.ensure_window()
Builder.load_string ('''
<MoodRing>:
Image:
source: 'colours.png'
size: (640,480)
''')
class MoodRing(Widget):
def __init__(self):
super(MoodRing, self).__init__()
self.tex = Image('colours2.png')
self.tex2 = Image('colours3.png')
self.size = (640,480)
self.mood = get_random_color()
with self.canvas:
self.fbo = Fbo(size=(self.size), with_depthbuffer = True)
Rectangle(size = (640,480), texture = self.fbo.texture)
self.new_color()
def update(self, *args):
self.color.rgba = self.mood
def animate_color(self, *args):
self.color.rgba = self.mood
anim = Animation(mood = get_random_color(), duration = 1.5, t = 'in_out_cubic')
#Clock.schedule_interval(self.update, 1/30.)
anim.start(self)
#gc.collect()
print Clock.get_rfps()
def new_color(self, *args):
with self.fbo:
self.color = Color(self.mood[0], self.mood[1],self.mood[2],self.mood[3])
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
Rectangle(size = (640,480), texture = self.tex.texture)
class MoodRingApp(App):
def build(self):
moodring = MoodRing()
mood = Label(text = 'punctilious', font_size = '72sp', pos = (0,-200))
relative = RelativeLayout(pos = (40,240))
root = FloatLayout(orientation = 'vertical', size = (720,720))
Clock.schedule_interval(moodring.animate_color, 3.)
Clock.schedule_interval(moodring.update, 0)
relative.add_widget(moodring)
root.add_widget(relative)
root.add_widget(mood)
return root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment