Recording gestures – line, circles, and cross
What about drawing with one finger? Can we recognize gestures? It is possible to do this with Kivy, but first we need to record the gestures that we want to use. A gesture is represented as a long string that contains the points of a stroke over the screen. The following code is not part of the project and can be run with python gesturerecorder.py
:
170. # File Name: gesturerecorder.py 171. from kivy.app import App 172. from kivy.uix.floatlayout import FloatLayout 173. from kivy.graphics import Line, Ellipse 174. from kivy.gesture import Gesture, GestureDatabase 175. 176. class GestureRecorder(FloatLayout): 177. 178. def on_touch_down(self, touch): 179. self.points = [touch.pos] 180. with self.canvas: 181. Ellipse(pos=(touch.x-5,touch.y-5),size=(10,10)) 182. self.line = Line(points=(touch.x, touch.y)) 183. 184. def on_touch_move(self, touch): 185. self.points += [touch.pos] 186. ...