1 from operationscore.Behavior import *
2 from logger import main_log
3
4 import colorsys
5 from numpy import array
6 import pdb
7 import util.ComponentRegistry as compReg
8
9 speedfactor = 15
10 vel_decay = .9
11
13 if v[0] > c[0]:
14 v[0] = c[0]
15 elif v[0]<0:
16 v[0] = 0
17
18 if v[1] > c[1]:
19 v[1] = c[1]
20 elif v[1]<0:
21 v[1] = 0
22
23 return v
24
27 self.xy = array((0,0))
28 self.v_xy = array((0,0))
29 self.v_decay = vel_decay
30
31 self.start_hsv = [0,1,1]
32 self.dest_hsv = [0,1,1]
33 self.ssize = compReg.getComponent('Screen').getSize()[-2:]
34
36 ret = []
37 if sensorInputs:
38 data = sensorInputs[-1]
39 if data['Path'] == '/sixaxis/xy':
40
41 x = data['Value'][0]
42 y = data['Value'][1]
43 if y < 0:
44 self.start_hsv[1] = 1.0+y
45 else:
46 self.start_hsv[2] = 1.0-y
47 self.start_hsv[0] = (x+1)/2.
48 elif data['Path'] == '/sixaxis/lrud':
49 val=data['Value']
50 vy = val[3]-val[2]
51 vx = val[1]-val[0]
52
53
54 self.v_xy = array((vx, vy)) * speedfactor
55 else:
56 main_log.error('Sensor Inputs: ' + str(sensorInputs))
57 self.xy = self.xy + self.v_xy
58 constrainLocation(self.xy,self.ssize)
59 self.v_xy *= self.v_decay
60 ret.append({'Color':[i*255. for i in colorsys.hsv_to_rgb(*self.start_hsv)],'Location':(int(self.xy[0]), int(self.xy[1]))})
61
62 return (ret, [])
63