Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import sys
- import random
- import struct
- import time
- host = '127.0.0.1'
- port = 3425
- def send_pixel(s, x, y, color):
- msg = struct.pack("hhccc", x, y, *[chr(q) for q in color])
- #print len(msg), "'" + msg + "'"
- s.sendto(msg, (host, port))
- def send_image_file(s, filename):
- from PIL import Image
- img = Image.open(filename)
- img_data = img.load()
- width, height = img.size
- for x in range(width):
- for y in range(height):
- send_pixel(s, x, y, img_data[x,y])
- def send_image_file_random(s, filename):
- from PIL import Image
- img = Image.open(filename)
- img_data = img.load()
- width, height = img.size
- while 1:
- x = random.randint(0, width-1)
- y = random.randint(0, height-1)
- send_pixel(s, x, y, img_data[x,y])
- time.sleep(0.001)
- if __name__ == "__main__":
- try:
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- except:
- print "Failed to create socket"
- sys.exit()
- send_image_file_random(s, sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement