Mercurial > hg > mood-conductor
comparison visualclient/visclient.py @ 31:1233c13c17d9
indicators use gfxdraw anti aliasing
author | gyorgyf |
---|---|
date | Mon, 29 Apr 2013 16:02:54 +0100 |
parents | 4a7fde8ff0fd |
children | cb57e554ae80 |
comparison
equal
deleted
inserted
replaced
30:4a7fde8ff0fd | 31:1233c13c17d9 |
---|---|
8 """ | 8 """ |
9 | 9 |
10 import sys,os,math,time,copy | 10 import sys,os,math,time,copy |
11 import pygame as pg | 11 import pygame as pg |
12 from pygame.locals import * | 12 from pygame.locals import * |
13 from pygame import gfxdraw as gd | |
13 import httplib as ht | 14 import httplib as ht |
14 | 15 |
15 import gradients | 16 import gradients |
16 from gradients import genericFxyGradient | 17 from gradients import genericFxyGradient |
17 | 18 |
18 from threading import Thread | 19 from threading import Thread |
19 from random import random | 20 from random import random |
20 | 21 |
21 import colorsys as cs | 22 import colorsys as cs |
22 | |
23 # from pytagcloud import create_tag_image, make_tags | |
24 # from pytagcloud.lang.counter import get_tag_counts | |
25 | |
26 # YOUR_TEXT = "A tag cloud is a visual representation for text data, typically\ | |
27 # used to depict keyword metadata on websites, or to visualize free form text." | |
28 # | |
29 # tags = make_tags(get_tag_counts(YOUR_TEXT), maxsize=120) | |
30 # | |
31 # create_tag_image(tags, 'cloud_large.png', size=(900, 600), fontname='Lobster') | |
32 | 23 |
33 scol = (0,255,0,255) | 24 scol = (0,255,0,255) |
34 ecol = (0,0,0,255) | 25 ecol = (0,0,0,255) |
35 | 26 |
36 # X,Y=1140,900 | 27 # X,Y=1140,900 |
85 self.xs = int(self.x * X) | 76 self.xs = int(self.x * X) |
86 self.ys = int(Y - (self.y * Y)) | 77 self.ys = int(Y - (self.y * Y)) |
87 | 78 |
88 def draw(self): | 79 def draw(self): |
89 if self.visible : | 80 if self.visible : |
90 pg.draw.circle(self.bg, self.c, (self.xs,self.ys),self.size,0) | 81 # pg.draw.circle(self.bg, self.c, (self.xs,self.ys),self.size,0) |
82 # gd.aacircle(self.bg, self.xs, self.ys, self.size+1, self.c) | |
83 gd.filled_circle(self.bg, self.xs, self.ys, self.size, self.c) | |
84 gd.aacircle(self.bg, self.xs, self.ys, self.size, self.c) | |
85 | |
91 | 86 |
92 def toggle(self): | 87 def toggle(self): |
93 if self.ison == True : | 88 if self.ison == True : |
94 self.off() | 89 self.off() |
95 else : | 90 else : |
568 | 563 |
569 | 564 |
570 def reconnect(self): | 565 def reconnect(self): |
571 '''Called when c is pressed.''' | 566 '''Called when c is pressed.''' |
572 self.init_reconnect = False | 567 self.init_reconnect = False |
573 # self.indicators["conn"].off().draw() | |
574 # self.screen.blit(self.bg, (0, 0)) | |
575 # pg.display.flip() | |
576 | 568 |
577 self.stop_update_thread() | 569 self.stop_update_thread() |
578 time.sleep(1) | 570 time.sleep(1) |
579 try : | 571 try : |
580 self.conn.close() | 572 self.conn.close() |
596 self.indicators["conn"].off() | 588 self.indicators["conn"].off() |
597 self.stop_update_thread() | 589 self.stop_update_thread() |
598 self.conn.close() | 590 self.conn.close() |
599 pg.quit() | 591 pg.quit() |
600 sys.exit() | 592 sys.exit() |
601 | |
602 | |
603 | |
604 | 593 |
605 | 594 |
606 def main(): | 595 def main(): |
607 | 596 |
608 v = VisualClient() | 597 v = VisualClient() |
609 v.run() | 598 v.run() |
610 | |
611 # conn = ht.HTTPConnection("192.168.2.184:8030") | |
612 # | |
613 # pg.init() | |
614 # fontObj = pg.font.Font("freesansbold.ttf",18) | |
615 # | |
616 # white = ( 255, 255, 255) | |
617 # black = ( 0,0,0) | |
618 # fpsClock = pg.time.Clock() | |
619 # screen = pg.display.set_mode((1024, 768)) | |
620 # rect_x,rect_y=50,50 | |
621 # rect_xp,rect_yp=50,50 | |
622 # rect_change_x,rect_change_y=5,5 | |
623 # counter = 0 | |
624 # scol = (0,255,0,255) | |
625 # # ecol = (100,0,50,255) | |
626 # ecol = (0,0,0,255) | |
627 # coordstxt = "test" | |
628 # | |
629 # while True : | |
630 # pg.draw.circle(screen, pg.Color(255,0,0), (300,50),20,0) | |
631 # # screen.blit(gradients.radial(99, scol, ecol), (401, 1)) | |
632 # | |
633 # for event in pg.event.get() : | |
634 # if event.type == QUIT: | |
635 # conn.close() | |
636 # pg.quit() | |
637 # sys.exit() | |
638 # elif event.type == KEYDOWN : | |
639 # if event.key == K_ESCAPE : | |
640 # pg.event.post(pg.event.Event(QUIT)) | |
641 # | |
642 # # put text | |
643 # # txtObj = fontObj.render(coordstxt,True,pg.Color(254,254,254)) | |
644 # # rectObj = txtObj.get_rect() | |
645 # # rectObj.topleft = (10,20) | |
646 # # # rectObj.fill(pg.Color(254,254,254)) | |
647 # # screen.blit(txtObj,rectObj) | |
648 # | |
649 # | |
650 # # Draw the rectangle | |
651 # # pg.draw.rect(screen,black,[rect_xp,rect_yp,50,50]) | |
652 # screen.blit(gradients.radial(19, ecol, ecol), (rect_xp,rect_yp)) | |
653 # | |
654 # rect_xp,rect_yp = rect_x,rect_y | |
655 # # pg.draw.rect(screen,white,[rect_x,rect_y,50,50]) | |
656 # screen.blit(gradients.radial(19, scol, ecol), (rect_x,rect_y)) | |
657 # | |
658 # | |
659 # # Move the rectangle starting point | |
660 # # rect_x += rect_change_x | |
661 # # rect_y += rect_change_y | |
662 # counter += 1 | |
663 # if counter % 12 : | |
664 # counter = 0 | |
665 # try : | |
666 # conn.request("GET","/moodconductor/result") | |
667 # res = conn.getresponse() | |
668 # data = eval(res.read()) | |
669 # coordstxt = "x:%s y:%s" %data | |
670 # rect_x = data[0] * 300 | |
671 # rect_y = data[1] * 1000 | |
672 # conn.close() | |
673 # except : | |
674 # pass | |
675 # | |
676 # | |
677 # | |
678 # # Bounce the ball if needed | |
679 # if rect_y > 450 or rect_y < 0: | |
680 # rect_change_y = rect_change_y * -1 | |
681 # if rect_x > 650 or rect_x < 0: | |
682 # rect_change_x = rect_change_x * -1 | |
683 # | |
684 # # pg.display.update() | |
685 # pg.display.flip() | |
686 # fpsClock.tick(50) | |
687 # | |
688 # | |
689 # # if raw_input("quit?") in ['y'] : | |
690 # # pg.quit() | |
691 # | |
692 # pass | |
693 | |
694 | 599 |
695 if __name__ == '__main__': | 600 if __name__ == '__main__': |
696 pass | 601 pass |
697 main() | 602 main() |
698 | 603 |