vpu_live.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import pygame
  2. import pygame.gfxdraw
  3. import math
  4. import random
  5. import os
  6. os.environ['SDL_VIDEO_WINDOW_POS'] = '%i,%i' % (200,200)
  7. os.environ['SDL_VIDEO_CENTERED'] = '0'
  8. pg = pygame
  9. pygame.init()
  10. main_size=(600,300)
  11. main_size=(1600,900)
  12. main_size=(600,300)
  13. #window = pygame.display.set_mode(main_size,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  14. #window = pygame.display.set_mode(main_size,pg.RESIZABLE|pygame.DOUBLEBUF,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  15. window = pygame.display.set_mode(main_size,pg.RESIZABLE)#,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  16. #window = pygame.display.set_mode(main_size,pg.NOFRAME,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  17. #window = pygame.display.set_mode(main_size,pg.NOFRAME,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  18. #window = pygame.display.set_mode(main_size,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  19. # pygame.display.set_mode((self.width, int(self.height+(self.height*0.15))) ,pygame.FULLSCREEN)
  20. #pg.display.set_mode(window,pg.DOUBLEBUF) #|pg.OPENGL)
  21. pg.display.set_caption('LibreLight Animation')
  22. import pygame
  23. import pygame.gfxdraw
  24. import math
  25. import random
  26. import os
  27. def event_read():
  28. inc = 1
  29. for event in pg.event.get():
  30. print("event",event)
  31. move_x = 0
  32. move_y = 0
  33. move_z = 0
  34. rot_x = 0
  35. rot_y = 0
  36. rot_z = 0
  37. if event.type== pg.QUIT:
  38. print("quit")
  39. pg.quit()
  40. quit()
  41. sys.exit()
  42. if "key" in dir(event):
  43. if event.key == 27: #ESC pg.KEYDOWN:
  44. print("quit")
  45. pg.quit()
  46. quit()
  47. sys.exit()
  48. pg = pygame
  49. pygame.init()
  50. main_size=(600,300)
  51. main_size=(1600,900)
  52. main_size=(600,300)
  53. #window = pygame.display.set_mode(main_size,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  54. #window = pygame.display.set_mode(main_size,pg.RESIZABLE|pygame.DOUBLEBUF,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  55. window = pygame.display.set_mode(main_size,pg.RESIZABLE)#,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  56. #window = pygame.display.set_mode(main_size,pg.NOFRAME,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  57. #window = pygame.display.set_mode(main_size,pg.NOFRAME,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  58. #window = pygame.display.set_mode(main_size,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  59. # pygame.display.set_mode((self.width, int(self.height+(self.height*0.15))) ,pygame.FULLSCREEN)
  60. #pg.display.set_mode(window,pg.DOUBLEBUF) #|pg.OPENGL)
  61. pg.display.set_caption('LibreLight Animation')
  62. class FIX():
  63. def __init__(self,pos=[10,10]):
  64. self.rgb = [255,255,255]
  65. self.pos = pos
  66. def draw(self):
  67. pygame.draw.rect(window,self.rgb,[self.pos[0],self.pos[1],15,15])
  68. import memcache
  69. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  70. import time
  71. s=time.time()
  72. import math
  73. while 1:
  74. x=mc.get("index")#cmd)
  75. #for i,k in x.items():
  76. # print(i,k)
  77. t = int(math.sin(time.time() - s)*10)
  78. event_read()
  79. #r=mc.get("10.10.10.13:2")
  80. r = mc.get("2.0.0.13:2")
  81. if not r:
  82. c = 0
  83. time.sleep(0.1)
  84. r = [0] *512
  85. #for i in range(12+1):
  86. # for j in range(8+1):
  87. # dmx = i*j*4 #*j*4
  88. # if c == 1:
  89. # col = [255,255,0,0]
  90. for i in range(12*8+1):
  91. dmx = i*4
  92. r[dmx:dmx+4] = [255,10,10,40]
  93. #print(r)
  94. ch = 0
  95. dmx = 1-1
  96. rgb = [255,255,255]
  97. for x in range(12):
  98. for y in range(8):
  99. ch += 4
  100. #f = FIX(pos=[x*16,y*16])
  101. if ch+4 < len(r):
  102. rgb = [r[ch+1]*r[ch]/255,r[ch+2]*r[ch]/255,r[ch+3]*r[ch]/255]
  103. #print(rgb)
  104. pos=[x*16,y*16]
  105. pygame.draw.rect(window,rgb,[pos[0],pos[1],15,15])
  106. #f.draw()
  107. pygame.display.flip()
  108. pg.time.wait(10)