Last active
August 29, 2015 13:57
-
-
Save amalgamatedclyde/9722139 to your computer and use it in GitHub Desktop.
why does this kill the framerate?
This file contains 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
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() | |
import objgraph | |
import gc | |
import graphviz | |
import xdot | |
Builder.load_string (''' | |
<MoodRing>: | |
Image: | |
source: 'ring5.png' | |
size: (640,480) | |
''') | |
class MoodRing(Widget): | |
def __init__(self): | |
super(MoodRing, self).__init__() | |
self.tex = Image('jewel5.png') | |
self.tex2 = Image('ring5.png') | |
self.size = (640,480) | |
self.mood = get_random_color() | |
self.ellipse = Ellipse(size = (203,279), pos = (224,115)) | |
self.rectangle = Rectangle(size = (640,480), texture = self.tex.texture) | |
self.color = Color(self.mood[0], self.mood[1],self.mood[2],self.mood[3]) | |
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.canvas.ask_update() | |
def animate_color(self, *args): | |
t = self.new_color | |
t() | |
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: | |
Color(self.mood[0], self.mood[1],self.mood[2],self.mood[3]) | |
self.ellipse | |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) | |
Rectangle(size = (640,480), texture = self.tex.texture) | |
class MoodRingApp(App): | |
def __init__(self, **kwargs): | |
super(MoodRingApp, self).__init__(**kwargs) | |
#def showgraph(self): | |
##return (objgraph.show_growth(limit=5)) | |
#return objgraph.show_backrefs([Fbo]) | |
###return objgraph.show_backrefs([renderer], extra_info=lambda x: hex(id(x))) | |
#Clock.schedule_interval(showgraph, 6.) | |
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.new_color, 1/30.) | |
relative.add_widget(moodring) | |
root.add_widget(relative) | |
root.add_widget(mood) | |
return root | |
if __name__ == "__main__": | |
MoodRingApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment