# HG changeset patch # User gyorgyf # Date 1348909827 -3600 # Node ID 6022a370c7dd6a887c6a31f62af8a40faa5eaa1e # Parent c97feb7ef9e9834db1a55ac6ebc535c29ab24ad0 added Strasbourg version diff -r c97feb7ef9e9 -r 6022a370c7dd visualclient/visclient.py --- a/visualclient/visclient.py Thu Sep 20 23:55:48 2012 +0100 +++ b/visualclient/visclient.py Sat Sep 29 10:10:27 2012 +0100 @@ -18,6 +18,8 @@ from threading import Thread from random import random +import colorsys as cs + # from pytagcloud import create_tag_image, make_tags # from pytagcloud.lang.counter import get_tag_counts @@ -35,6 +37,19 @@ # X,Y = 600,400 X,Y = 800,600 +# Fullscreen resolution: +# XF,YF = 1280,900 +# XF,YF = 1440,900 +XF,YF = 1344,900 +# display calibrated + +# detect display resolution +import subprocess +screenres = subprocess.Popen('xrandr | grep "\*" | cut -d" " -f4',shell=True, stdout=subprocess.PIPE).communicate()[0] +screenres = map(lambda x: int(x.strip()), screenres.split('x')) +XF,YF = screenres +print "Screen resolution: ",XF,YF + NBLOBS = 18 BLOBSIZE = 25 G=110 @@ -130,7 +145,9 @@ def increment(self,count): self.time = time.time() self.count = count - self.size = int(BLOBSIZE * int(self.count/1.5)) + # self.size = int(BLOBSIZE * int(self.count/1.5)) + self.to = int(BLOBSIZE * int(self.count/1.5)) + self.start_animate() def get_distance(self,x,y): return math.sqrt( math.pow((self.x-x),2) + math.pow((self.y-y),2) ) @@ -141,6 +158,18 @@ def reset_time(self): self.time = time.time() + + def start_animate(self): + self.thread = Thread(target = self.animate) + self.thread.daemon = True + self.thread.start() + + def animate(self): + '''Animate the way bubbles are grown.''' + while self.size < self.to : + self.size += 1 + time_inc = 20.0 / (pow(1.2, self.to-self.size) * 200.0) + time.sleep(0.02+time_inc) @@ -219,10 +248,19 @@ 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]))) - # mood.color = tuple(map(lambda x: int(x),(colors[2],colors[3],colors[4]))) + # mood.color = tuple(map(lambda x: int(pow(math.atan((float(x)/7.0)),12.5)),(colors[2],colors[3],colors[4]))) + mood.color = self.set_color(tuple(map(lambda x: int(x),(colors[2],colors[3],colors[4])))) return True + def set_color(self,color): + '''Move to HLS colour space and manipulate saturation there.''' + # TODO: ideally, we need a non-linear compressor of the lightness and saturation values + r,g,b = map(lambda x: (1.0*x/255.0), color) + h,l,s = cs.rgb_to_hls(r,g,b) + s = 1.0 #1.0 - (1.0 / pow(50.0,s)) + l = 1.0 - (1.0 / pow(20.0,l)) #0.6 + r,g,b = map(lambda x: int(x*255), cs.hls_to_rgb(h,l,s)) + return r,g,b def start_update_thread(self): '''Start the thread that reads data from the server.''' @@ -365,9 +403,10 @@ if self.fullscreen == False: globals()['_X'] = globals()['X'] globals()['_Y'] = globals()['Y'] - globals()['X'] = 1440 - globals()['Y'] = 900 - self.screen = pg.display.set_mode((X, Y)) + globals()['X'] = XF + globals()['Y'] = YF + self.screen = pg.display.set_mode((X, Y)) + # self.screen = pg.display.set_mode((0,0),pg.FULLSCREEN) self.fullscreen = True self.bg = pg.Surface(self.screen.get_size()) self.bg = self.bg.convert() @@ -414,6 +453,28 @@ self.reconnect() return True + + def configure_server(self): + '''Send the server some configuration data.''' + age = 10.0 + dist = DIST + ninp = 18 + self.conn.putrequest("GET","/moodconductor/config?age=%(age)s&dist=%(dist)s&ninp=%(ninp)s" %locals(), skip_host=True) + self.conn.putheader("Host", "www.isophonics.net") + self.conn.endheaders() + res = self.conn.getresponse() + if not res.status == 200 : + print "Server response:", res.status, res.reason + self.indicators["conn"].off() + time.sleep(1) + self.conn.putrequest("GET","/moodconductor/getconf", skip_host=True) + self.conn.putheader("Host", "www.isophonics.net") + self.conn.endheaders() + res = self.conn.getresponse() + if not res.status == 200 : + print "Server response:", res.status, res.reason + self.indicators["conn"].off() + print "Server configuration:", res.read() def connect(self,retry = 5): @@ -456,6 +517,7 @@ else : self.noretry = None self.connect(retry = retry-1) + self.configure_server() self.start_update_thread() return True