Created
May 30, 2015 16:28
-
-
Save inclement/e76fb67e7cda72efc40d to your computer and use it in GitHub Desktop.
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 | |
| from kivy.uix.effectwidget import EffectWidget, EffectBase, AdvancedEffectBase | |
| from kivy.clock import Clock | |
| from random import random | |
| Builder.load_string(''' | |
| <Root>: | |
| Widget: | |
| canvas: | |
| Color: | |
| rgba: 1, 1, 1, 1 | |
| Rectangle: | |
| pos: self.pos | |
| size: self.size | |
| ''') | |
| effect_broken = ''' | |
| uniform float randone; | |
| uniform float randtwo; | |
| vec3 hsv2rgb(vec3 c) | |
| { | |
| vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); | |
| vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); | |
| return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); | |
| } | |
| float rand(vec2 co){ | |
| return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); | |
| } | |
| vec4 effect( vec4 color, sampler2D buf0, vec2 texCoords, vec2 coords ) | |
| { | |
| float number = rand(texCoords + vec2(randone, randtwo)); | |
| return vec4(hsv2rgb( vec3(number, 1.0, 1.0)), 1.0); | |
| } | |
| ''' | |
| class BrokenEffect(AdvancedEffectBase): | |
| def __init__(self): | |
| super(BrokenEffect, self).__init__() | |
| self.glsl = effect_broken | |
| self.uniforms = {'randone': random(), | |
| 'randtwo': random()} | |
| Clock.schedule_interval(self.set_random_uniforms, 0) | |
| def set_random_uniforms(self, dt): | |
| self.uniforms['randone'] = random() | |
| self.uniforms['randtwo'] = random() | |
| class Root(EffectWidget): | |
| def __init__(self): | |
| super(Root, self).__init__() | |
| self.effects = [BrokenEffect()] | |
| class BrokenApp(App): | |
| def build(self): | |
| return Root() | |
| BrokenApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment