Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. import socket
  2. import sys
  3. import random
  4. import struct
  5. import time
  6.  
  7. host = '127.0.0.1'
  8. port = 3425
  9.  
  10. def send_pixel(s, x, y, color):
  11.     msg = struct.pack("hhccc", x, y, *[chr(q) for q in color])
  12.     #print len(msg), "'" + msg + "'"
  13.     s.sendto(msg, (host, port))
  14.  
  15. def send_image_file(s, filename):
  16.     from PIL import Image
  17.     img = Image.open(filename)
  18.     img_data = img.load()
  19.     width, height = img.size
  20.     for x in range(width):
  21.         for y in range(height):
  22.             send_pixel(s, x, y, img_data[x,y])
  23.  
  24. def send_image_file_random(s, filename):
  25.     from PIL import Image
  26.     img = Image.open(filename)
  27.     img_data = img.load()
  28.     width, height = img.size
  29.     while 1:
  30.         x = random.randint(0, width-1)
  31.         y = random.randint(0, height-1)
  32.         send_pixel(s, x, y, img_data[x,y])
  33.         time.sleep(0.001)
  34.  
  35.  
  36. if __name__ == "__main__":
  37.     try:
  38.         s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  39.     except:
  40.         print "Failed to create socket"
  41.         sys.exit()
  42.        
  43.     send_image_file_random(s, sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement