comparison visualclient/visclient.py @ 5:1adf97ba90c8

added visual client
author gyorgyf
date Thu, 21 Jun 2012 17:14:09 +0100
parents
children 9d9169751aba
comparison
equal deleted inserted replaced
4:02b4c5e122e8 5:1adf97ba90c8
1 #!/usr/bin/env python
2 # encoding: utf-8
3 """
4 visclient.py
5
6 Created by George Fazekas on 2012-06-17.
7 Copyright (c) 2012 . All rights reserved.
8 """
9
10 import sys,os
11 import pygame as pg
12 from pygame.locals import *
13 import httplib as ht
14
15 import gradients
16 from gradients import genericFxyGradient
17
18 # from pytagcloud import create_tag_image, make_tags
19 # from pytagcloud.lang.counter import get_tag_counts
20
21 # YOUR_TEXT = "A tag cloud is a visual representation for text data, typically\
22 # used to depict keyword metadata on websites, or to visualize free form text."
23 #
24 # tags = make_tags(get_tag_counts(YOUR_TEXT), maxsize=120)
25 #
26 # create_tag_image(tags, 'cloud_large.png', size=(900, 600), fontname='Lobster')
27
28
29
30 def main():
31
32 conn = ht.HTTPConnection("192.168.2.184:8030")
33
34 pg.init()
35 fontObj = pg.font.Font("freesansbold.ttf",18)
36
37 white = ( 255, 255, 255)
38 black = ( 0,0,0)
39 fpsClock = pg.time.Clock()
40 screen = pg.display.set_mode((1024, 768))
41 rect_x,rect_y=50,50
42 rect_xp,rect_yp=50,50
43 rect_change_x,rect_change_y=5,5
44 counter = 0
45 scol = (0,255,0,255)
46 # ecol = (100,0,50,255)
47 ecol = (0,0,0,255)
48 coordstxt = "test"
49
50 while True :
51 pg.draw.circle(screen, pg.Color(255,0,0), (300,50),20,0)
52 # screen.blit(gradients.radial(99, scol, ecol), (401, 1))
53
54 for event in pg.event.get() :
55 if event.type == QUIT:
56 conn.close()
57 pg.quit()
58 sys.exit()
59 elif event.type == KEYDOWN :
60 if event.key == K_ESCAPE :
61 pg.event.post(pg.event.Event(QUIT))
62
63 # put text
64 txtObj = fontObj.render(coordstxt,True,pg.Color(254,254,254))
65 rectObj = txtObj.get_rect()
66 rectObj.topleft = (10,20)
67 # rectObj.fill(pg.Color(254,254,254))
68 screen.blit(txtObj,rectObj)
69
70
71 # Draw the rectangle
72 # pg.draw.rect(screen,black,[rect_xp,rect_yp,50,50])
73 screen.blit(gradients.radial(99, ecol, ecol), (rect_xp,rect_yp))
74
75 rect_xp,rect_yp = rect_x,rect_y
76 # pg.draw.rect(screen,white,[rect_x,rect_y,50,50])
77 screen.blit(gradients.radial(99, scol, ecol), (rect_x,rect_y))
78
79
80 # Move the rectangle starting point
81 # rect_x += rect_change_x
82 # rect_y += rect_change_y
83 counter += 1
84 if counter % 12 :
85 counter = 0
86 try :
87 conn.request("GET","/moodconductor/result")
88 res = conn.getresponse()
89 data = eval(res.read())
90 coordstxt = "x:%s y:%s" %data
91 rect_x = data[0] * 300
92 rect_y = data[1] * 1000
93 conn.close()
94 except :
95 pass
96
97
98
99 # Bounce the ball if needed
100 if rect_y > 450 or rect_y < 0:
101 rect_change_y = rect_change_y * -1
102 if rect_x > 650 or rect_x < 0:
103 rect_change_x = rect_change_x * -1
104
105 # pg.display.update()
106 pg.display.flip()
107 fpsClock.tick(50)
108
109
110 # if raw_input("quit?") in ['y'] :
111 # pg.quit()
112
113 pass
114
115
116 if __name__ == '__main__':
117 pass
118 main()
119