class Listener(Leap.Listener): def on_connect(self, controller): print "Connected" self.drawing = Drawing() self.prev_pot = 400 self.prev_button = 1 # controller.enable_gesture(Leap.Gesture.TYPE_SWIPE); def on_frame(self, controller): frame = controller.frame() #print "Frame id: %d, timestamp: %d, hands: %d, fingers: %d, tools: %d, gestures: %d" % ( #frame.id, frame.timestamp, len(frame.hands), len(frame.fingers), len(frame.tools), len(frame.gestures())) if len(frame.tools) > 0: pen = frame.tools[0] reading = ser.readline() #print reading try: pot = int(reading.split(' ')[0]) button = int(reading.split(' ')[1][0]) self.prev_pot = pot self.prev_button = button #print (pot, button) except: pot = self.prev_pot button = self.prev_button print 'Invalid reading' radius = float(pot-low_pot)/(high_pot-low_pot)*(high_radius-low_radius) + low_radius if True: print ('position: ' + str(pen.tip_position), 'radius: ' + str(radius)) self.drawing.add_sphere(Sphere(pen.tip_position, radius))