Skip to content

Instantly share code, notes, and snippets.

@inclement
Created April 20, 2014 17:50
Show Gist options
  • Select an option

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

Select an option

Save inclement/11120383 to your computer and use it in GitHub Desktop.
from kivy.base import runTouchApp
from kivy.properties import ListProperty
from kivy.lang import Builder
from kivy.uix.effectwidget import EffectWidget, EffectBase, AdvancedEffectBase, InvertEffect
effect_string = '''
uniform vec2 touch;
vec4 effect(vec4 color, sampler2D texture, vec2 tex_coords, vec2 coords)
{
vec2 distance = coords - touch;
float dist_mag = 10.0 * dot(distance, distance);
vec3 multiplier = vec3(abs(sin(dist_mag + time)));
return vec4(multiplier * color.xyz, color.w);
}
'''
class TouchEffect(AdvancedEffectBase):
touch = ListProperty([0.0, 0.0])
def __init__(self, *args, **kwargs):
super(TouchEffect, self).__init__(*args, **kwargs)
self.glsl = effect_string
self.uniforms = {'touch': [0.0, 0.0]}
def on_touch(self, *args, **kwargs):
self.uniforms['touch'] = [float(i) for i in self.touch]
class TouchWidget(EffectWidget):
def __init__(self, *args, **kwargs):
super(TouchWidget, self).__init__(*args, **kwargs)
self.effect = TouchEffect()
self.effects = [self.effect]
def on_touch_down(self, touch):
super(TouchWidget, self).on_touch_down(touch)
self.on_touch_move(touch)
def on_touch_move(self, touch):
self.effect.touch = touch.pos
root = Builder.load_string('''
TouchWidget:
Button:
text: 'Some text!'
Image:
source: 'data/logo/kivy-icon-512.png'
allow_stretch: True
keep_ratio: False
''')
runTouchApp(root)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment