Mercurial > hg > mood-conductor
diff visualclient/visclient.py @ 22:858fc44a17c1
added s option to stop blobs from fading
author | gyorgyf |
---|---|
date | Fri, 22 Jun 2012 16:52:57 +0100 |
parents | 92903c908539 |
children | c97feb7ef9e9 |
line wrap: on
line diff
--- a/visualclient/visclient.py Fri Jun 22 16:02:14 2012 +0100 +++ b/visualclient/visclient.py Fri Jun 22 16:52:57 2012 +0100 @@ -31,13 +31,13 @@ # X,Y=1140,900 X,Y = 600,400 NBLOBS = 15 -BLOBSIZE = 20 +BLOBSIZE = 25 G=110 -FADE = 40 +FADE = 15 class Blob(object): - def __init__(self,bg,x,y,color=(255,255,255),mood=None): + def __init__(self,bg,x,y,color=(255,255,255),mood=None,fade=FADE): self.x = x self.y = y self.xs = x * X @@ -49,6 +49,7 @@ self.c = color self.count = 1 self.visible = True + self.FADE = fade if mood and mood.color : self.c = mood.color @@ -62,7 +63,7 @@ def draw(self): 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()*FADE) + self.alpha = 255 - int(self.age()*self.FADE) if self.alpha < 5 : self.alpha = 1 self.visible = False @@ -77,6 +78,13 @@ def get_distance(self,x,y): return math.sqrt( math.pow((self.x-x),2) + math.pow((self.y-y),2) ) + + def fade(self,fade): + if not fade : self.alpha = 255 + self.FADE = fade + + def reset_time(self): + self.time = time.time() @@ -123,6 +131,8 @@ # pg.quit() # sys.exit(-1) + self.FADE = FADE + pass def read_mood_data(self): @@ -133,19 +143,29 @@ l = line.split(',') mood = Mood(l[0],l[1],l[2]) self.moods.append(mood) - with open('feelings.txt') as ff: - data = ff.readlines() - data = map(lambda x: x.split('\t'),data) + # with open('feelings.txt') as ff: + # data = ff.readlines() + # data = map(lambda x: x.split('\t'),data) + # for mood in self.moods : + # for colors in data : + # if mood.word == colors[0] : + # mood.color = colors[2] + with open('colors.txt') as ff: + data = ff.readlines()[1:] + data = map(lambda x: x.split(','),data) for mood in self.moods : + d = cd = sys.float_info.max for colors in data : - if mood.word == colors[0] : - mood.color = colors[2] - pass - for mood in self.moods: - if mood.color : - mood.color = map(lambda x: '0x'+str(x).strip(),[mood.color[0:2],mood.color[2:4],mood.color[4:]]) - mood.color = tuple(map(lambda x: int(eval(x)),mood.color)) - # print mood.color + d = mood.get_distance(float(colors[0]),float(colors[1])) + if d < cd : + cd = d + mood.color = tuple(map(lambda x: int(pow(math.atan((float(x)/7.0)),12.5)),(colors[2],colors[3],colors[4]))) + + # for mood in self.moods: + # if mood.color : + # # mood.color = map(lambda x: '0x'+str(x).strip(),[mood.color[0:2],mood.color[2:4],mood.color[4:]]) + # mood.color = tuple(map(lambda x: int(x),mood.color)) + # print mood.color def update(self): @@ -177,7 +197,7 @@ cd = d cmood = mood - new = Blob(self.bg,x,y,mood=cmood) + new = Blob(self.bg,x,y,mood=cmood,fade=self.FADE) if not new in self.blobs : self.blobs.insert(0,new) elif c > self.blobs[self.blobs.index(new)].count: @@ -222,6 +242,22 @@ elif event.type == KEYDOWN : if event.key == K_ESCAPE : pg.event.post(pg.event.Event(QUIT)) + elif event.key == K_SPACE : + self.blobs = [] + elif event.key == K_s : + if self.FADE : + print "fade off" + self.FADE = 0 + for blob in self.blobs : + blob.fade(0) + else: + print "fade on" + self.FADE = 15 + for blob in self.blobs : + blob.fade(15) + blob.reset_time() + + # Draw