Mercurial > hg > mood-conductor
changeset 14:3bc0521eff28
some server updates
author | gyorgyf |
---|---|
date | Fri, 22 Jun 2012 13:41:40 +0100 |
parents | 7c00be58d9cf |
children | de603f9b7cfd |
files | visualclient/visclient.py |
diffstat | 1 files changed, 23 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/visualclient/visclient.py Fri Jun 22 11:56:31 2012 +0100 +++ b/visualclient/visclient.py Fri Jun 22 13:41:40 2012 +0100 @@ -30,6 +30,8 @@ # X,Y=1140,900 X,Y = 600,400 +BLOBSIZE = 20 +G=110 class Blob(object): @@ -39,10 +41,11 @@ self.xs = x * X self.ys = Y - (y * Y) self.bg = bg - self.size = 20 + self.size = BLOBSIZE self.time = time.time() self.alpha = 255 self.c = color + self.count = 1 self.visible = True if mood and mood.color : self.c = mood.color @@ -55,7 +58,8 @@ return -1 def draw(self): - 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,self.ys)) + d=int(self.size) + 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)) self.alpha = 255 - int(self.age()*15) if self.alpha < 5 : self.alpha = 1 @@ -65,7 +69,8 @@ return time.time() - self.time def increment(self,count): - self.size = int(self.size * int(count/1.5)) + self.count = count + self.size = int(BLOBSIZE * int(self.count/1.5)) def get_distance(self,x,y): return math.sqrt( math.pow((self.x-x),2) + math.pow((self.y-y),2) ) @@ -123,7 +128,7 @@ data = mf.readlines()[1:] for line in data : l = line.split(',') - mood = Mood(l[1],l[3],l[5]) + mood = Mood(l[0],l[1],l[2]) self.moods.append(mood) with open('feelings.txt') as ff: data = ff.readlines() @@ -153,17 +158,13 @@ self.conn.endheaders() res = self.conn.getresponse() data = res.read() - print data data = eval(data) if not data : self.conn.close() return False for d in data : - print d - coordstxt = "x:%s y:%s c:%s" %d - x = d[0] - y = d[1] - c = d[2] + # coordstxt = "x:%s y:%s c:%s" %d + x,y,c = d cmood = None d = cd = sys.float_info.max @@ -171,12 +172,12 @@ d = mood.get_distance(x,y) if d < cd : cd = d - cmood = mood + cmood = mood new = Blob(self.bg,x,y,mood=cmood) if not new in self.blobs : self.blobs.insert(0,new) - elif c > 2: + elif c > self.blobs[self.blobs.index(new)].count: self.blobs[self.blobs.index(new)].increment(c) self.conn.close() @@ -185,8 +186,6 @@ def draw(self): - # bg.blit(gradients.radial(19, ecol, ecol), (rect_xp,rect_yp)) - # rect_xp,rect_yp = rect_x,rect_y self.bg.fill((0,0,0)) # self.bg.blit(gradients.radial(19, self.scol, self.ecol), (rect_x,rect_y)) l = copy.copy(self.blobs) @@ -194,6 +193,11 @@ for blob in l : blob.draw() + # axis + pg.draw.line(self.bg, (G,G,G), (int(X/2.0),0),(int(X/2.0),Y), 1) + pg.draw.line(self.bg, (G,G,G), (0,int(Y/2.0)),(X,int(Y/2.0)), 1) + + def run(self): # conn = ht.HTTPConnection("192.168.2.184:8030") @@ -209,7 +213,7 @@ for event in pg.event.get() : if event.type == QUIT: - conn.close() + self.conn.close() pg.quit() sys.exit() elif event.type == KEYDOWN : @@ -225,13 +229,10 @@ counter += 1 if counter % 12 : counter = 0 - self.update() - - # try : - # rect_x,rect_y = self.update() - # except : - # pass - + try : + self.update() + except: + pass # update display self.screen.blit(self.bg, (0, 0)) pg.display.flip()