Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python
- import colorsys
- import random
- import socket
- import struct
- import sys
- HOST = '10.208.42.159'
- #HOST = '192.168.64.124'
- PORT = 5004
- dimx = 128
- dimy = 16
- def rand():
- return random.randint(0, 4000000000)
- def pixel(pixels):
- sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- # s = ''
- s = struct.pack("<B", 1) + struct.pack("<?", 0)
- for x, y, r, g, b in pixels:
- # s += 'PX %d %d %02x%02x%02x\n' % (x, y, r, g, b)
- s += struct.pack("<2H3B", x, y, r, g, b)
- # print len(s)
- sock.sendto(s, (HOST, PORT))
- del sock
- while True:
- pixels = []
- if len(sys.argv) == 1 or sys.argv[1] == 'random':
- for n in range(0, dimx * dimy):
- r, g, b = colorsys.hls_to_rgb(random.random(), 0.5, 1.0)
- pixels.append((rand() % dimx, rand() % dimy, int(r * 255), int(g * 255), int(b * 255)))
- elif sys.argv[1] == 'red':
- for n in range(0, dimx * dimy):
- pixels.append((rand() % dimx, rand() % dimy, 255, 0, 0))
- elif sys.argv[1] == 'blue':
- for n in range(0, dimx * dimy):
- pixels.append((rand() % dimx, rand() % dimy, 0, 0, 255))
- elif sys.argv[1] == 'green':
- for n in range(0, dimx * dimy):
- pixels.append((rand() % dimx, rand() % dimy, 0, 255, 0))
- pixel(pixels)
Advertisement
Add Comment
Please, Sign In to add comment