Skip to content

Instantly share code, notes, and snippets.

@hansent
Created March 15, 2010 09:03
Show Gist options
  • Save hansent/332641 to your computer and use it in GitHub Desktop.
Save hansent/332641 to your computer and use it in GitHub Desktop.
from pymt import *
class ScaleManipulation(MTWidget):
def init(self):
self.register_event_type('on_scale')
self.touches = []
self.distance = 0
def on_scale(self, scale):
self.parent.width *= scale
self.parent.height *= scale
def on_touch_down(self, touch):
if len(self.touches) < 2:
touch.grab(self)
self.touches.append(touch)
if len(self.touches) == 2:
self.distance = self.touches[0].distance(self.touches[1])
def on_touch_move(self, touch):
if len(self.touches) > 1:
old_distance = self.distance
self.distance = self.touches[0].distance(self.touches[1])
self.dispatch_event('on_scale', self.distance/old_distance)
def on_touch_up(self, touch):
if touch in self.touches:
self.touches.remove(touch)
rect = MTRectangularWidget()
rect.add_widget(ScaleManipulation())
runTouchApp(rect)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment