comparison visualclient/visclient.py @ 21:92903c908539

added colors from Matthias to visual client
author gyorgyf
date Fri, 22 Jun 2012 16:02:14 +0100
parents 3bc0521eff28
children 858fc44a17c1
comparison
equal deleted inserted replaced
20:e4790d4419c1 21:92903c908539
28 scol = (0,255,0,255) 28 scol = (0,255,0,255)
29 ecol = (0,0,0,255) 29 ecol = (0,0,0,255)
30 30
31 # X,Y=1140,900 31 # X,Y=1140,900
32 X,Y = 600,400 32 X,Y = 600,400
33 NBLOBS = 15
33 BLOBSIZE = 20 34 BLOBSIZE = 20
34 G=110 35 G=110
36 FADE = 40
35 37
36 class Blob(object): 38 class Blob(object):
37 39
38 def __init__(self,bg,x,y,color=(255,255,255),mood=None): 40 def __init__(self,bg,x,y,color=(255,255,255),mood=None):
39 self.x = x 41 self.x = x
58 return -1 60 return -1
59 61
60 def draw(self): 62 def draw(self):
61 d=int(self.size) 63 d=int(self.size)
62 self.bg.blit(gradients.radial(self.size, (self.c[0],self.c[1],self.c[2],self.alpha), (0,0,0,self.alpha)), (self.xs-d,self.ys-d)) 64 self.bg.blit(gradients.radial(self.size, (self.c[0],self.c[1],self.c[2],self.alpha), (0,0,0,self.alpha)), (self.xs-d,self.ys-d))
63 self.alpha = 255 - int(self.age()*15) 65 self.alpha = 255 - int(self.age()*FADE)
64 if self.alpha < 5 : 66 if self.alpha < 5 :
65 self.alpha = 1 67 self.alpha = 1
66 self.visible = False 68 self.visible = False
67 69
68 def age(self): 70 def age(self):
69 return time.time() - self.time 71 return time.time() - self.time
70 72
71 def increment(self,count): 73 def increment(self,count):
74 self.time = time.time()
72 self.count = count 75 self.count = count
73 self.size = int(BLOBSIZE * int(self.count/1.5)) 76 self.size = int(BLOBSIZE * int(self.count/1.5))
74 77
75 def get_distance(self,x,y): 78 def get_distance(self,x,y):
76 return math.sqrt( math.pow((self.x-x),2) + math.pow((self.y-y),2) ) 79 return math.sqrt( math.pow((self.x-x),2) + math.pow((self.y-y),2) )
179 self.blobs.insert(0,new) 182 self.blobs.insert(0,new)
180 elif c > self.blobs[self.blobs.index(new)].count: 183 elif c > self.blobs[self.blobs.index(new)].count:
181 self.blobs[self.blobs.index(new)].increment(c) 184 self.blobs[self.blobs.index(new)].increment(c)
182 185
183 self.conn.close() 186 self.conn.close()
184 self.blobs = self.blobs[:5] 187 self.blobs = self.blobs[:NBLOBS]
185 return True 188 return True
186 189
187 190
188 def draw(self): 191 def draw(self):
189 self.bg.fill((0,0,0)) 192 self.bg.fill((0,0,0))