flok99

Untitled

Jun 15th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. #! /usr/bin/python
  2.  
  3. import colorsys
  4. import random
  5. import socket
  6. import struct
  7. import sys
  8.  
  9. HOST = '10.208.42.159'
  10. #HOST = '192.168.64.124'
  11. PORT = 5004
  12.  
  13. dimx = 128
  14. dimy = 16
  15.  
  16. def rand():
  17.     return random.randint(0, 4000000000)
  18.  
  19. def pixel(pixels):
  20.     sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  21.  
  22. #    s = ''
  23.     s = struct.pack("<B", 1) + struct.pack("<?", 0)
  24.  
  25.     for x, y, r, g, b in pixels:
  26. #        s += 'PX %d %d %02x%02x%02x\n' % (x, y, r, g, b)
  27.         s += struct.pack("<2H3B", x, y, r, g, b)
  28.  
  29. #    print len(s)
  30.  
  31.     sock.sendto(s, (HOST, PORT))
  32.     del sock
  33.  
  34. while True:
  35.     pixels = []
  36.  
  37.     if len(sys.argv) == 1 or sys.argv[1] == 'random':
  38.         for n in range(0, dimx * dimy):
  39.             r, g, b = colorsys.hls_to_rgb(random.random(), 0.5, 1.0)
  40.             pixels.append((rand() % dimx, rand() % dimy, int(r * 255), int(g * 255), int(b * 255)))
  41.  
  42.     elif sys.argv[1] == 'red':
  43.         for n in range(0, dimx * dimy):
  44.             pixels.append((rand() % dimx, rand() % dimy, 255, 0, 0))
  45.  
  46.     elif sys.argv[1] == 'blue':
  47.         for n in range(0, dimx * dimy):
  48.             pixels.append((rand() % dimx, rand() % dimy, 0, 0, 255))
  49.  
  50.     elif sys.argv[1] == 'green':
  51.         for n in range(0, dimx * dimy):
  52.             pixels.append((rand() % dimx, rand() % dimy, 0, 255, 0))
  53.  
  54.     pixel(pixels)
Advertisement
Add Comment
Please, Sign In to add comment