Mercurial > hg > mood-conductor
view visualclient/visclient.py @ 5:1adf97ba90c8
added visual client
author | gyorgyf |
---|---|
date | Thu, 21 Jun 2012 17:14:09 +0100 |
parents | |
children | 9d9169751aba |
line wrap: on
line source
#!/usr/bin/env python # encoding: utf-8 """ visclient.py Created by George Fazekas on 2012-06-17. Copyright (c) 2012 . All rights reserved. """ import sys,os import pygame as pg from pygame.locals import * import httplib as ht import gradients from gradients import genericFxyGradient # from pytagcloud import create_tag_image, make_tags # from pytagcloud.lang.counter import get_tag_counts # YOUR_TEXT = "A tag cloud is a visual representation for text data, typically\ # used to depict keyword metadata on websites, or to visualize free form text." # # tags = make_tags(get_tag_counts(YOUR_TEXT), maxsize=120) # # create_tag_image(tags, 'cloud_large.png', size=(900, 600), fontname='Lobster') def main(): conn = ht.HTTPConnection("192.168.2.184:8030") pg.init() fontObj = pg.font.Font("freesansbold.ttf",18) white = ( 255, 255, 255) black = ( 0,0,0) fpsClock = pg.time.Clock() screen = pg.display.set_mode((1024, 768)) rect_x,rect_y=50,50 rect_xp,rect_yp=50,50 rect_change_x,rect_change_y=5,5 counter = 0 scol = (0,255,0,255) # ecol = (100,0,50,255) ecol = (0,0,0,255) coordstxt = "test" while True : pg.draw.circle(screen, pg.Color(255,0,0), (300,50),20,0) # screen.blit(gradients.radial(99, scol, ecol), (401, 1)) for event in pg.event.get() : if event.type == QUIT: conn.close() pg.quit() sys.exit() elif event.type == KEYDOWN : if event.key == K_ESCAPE : pg.event.post(pg.event.Event(QUIT)) # put text txtObj = fontObj.render(coordstxt,True,pg.Color(254,254,254)) rectObj = txtObj.get_rect() rectObj.topleft = (10,20) # rectObj.fill(pg.Color(254,254,254)) screen.blit(txtObj,rectObj) # Draw the rectangle # pg.draw.rect(screen,black,[rect_xp,rect_yp,50,50]) screen.blit(gradients.radial(99, ecol, ecol), (rect_xp,rect_yp)) rect_xp,rect_yp = rect_x,rect_y # pg.draw.rect(screen,white,[rect_x,rect_y,50,50]) screen.blit(gradients.radial(99, scol, ecol), (rect_x,rect_y)) # Move the rectangle starting point # rect_x += rect_change_x # rect_y += rect_change_y counter += 1 if counter % 12 : counter = 0 try : conn.request("GET","/moodconductor/result") res = conn.getresponse() data = eval(res.read()) coordstxt = "x:%s y:%s" %data rect_x = data[0] * 300 rect_y = data[1] * 1000 conn.close() except : pass # Bounce the ball if needed if rect_y > 450 or rect_y < 0: rect_change_y = rect_change_y * -1 if rect_x > 650 or rect_x < 0: rect_change_x = rect_change_x * -1 # pg.display.update() pg.display.flip() fpsClock.tick(50) # if raw_input("quit?") in ['y'] : # pg.quit() pass if __name__ == '__main__': pass main()