TouchTracer
Code
from pymt import *
class Tracer(MTWidget):
def on_touch_down(self, touch):
touch.userdata['trace'] = list(touch.pos)
def on_touch_move(self, touch):
touch.userdata['trace'].extend(touch.pos)
def draw(self):
set_color(1)
for touch in getCurrentTouches():
drawLine(touch.userdata['trace'])
runTouchApp(Tracer())
class Tracer(MTWidget):
def on_touch_down(self, touch):
touch.userdata['trace'] = list(touch.pos)
def on_touch_move(self, touch):
touch.userdata['trace'].extend(touch.pos)
def draw(self):
set_color(1)
for touch in getCurrentTouches():
drawLine(touch.userdata['trace'])
runTouchApp(Tracer())
Discussion
This application traces every touch that you make across the screen. Once a touch goes down, we start assembling a list of all the positions that specific touch was at. To store the information we add an entry to the touch's userdata dictionary.
When the touch moves, the new position the touch has moved to is added to the list we started for that touch. This works for any number of touches.
When the scene is drawn (which is controlled by PyMT), we just iterate over all currently available touches and use the drawLine function to draw a line between all stored positions of the respective touch. The drawLine function accepts a list of (x, y) coordinates and the touch.pos that we added to the list happens to be an (x, y) tuple.
