Skip to content

Instantly share code, notes, and snippets.

@mr1337357
Created January 24, 2018 01:47
Show Gist options
  • Save mr1337357/d846b6473cfae06d76868dac5fee596d to your computer and use it in GitHub Desktop.
Save mr1337357/d846b6473cfae06d76868dac5fee596d to your computer and use it in GitHub Desktop.
#!/usr/bin/python2
import socket
import random
import time
UDP_IP = '127.0.0.1'
UDP_PORT = 1235
IMAGES=["logo.txt","logo2.txt"]
def text2img(infile):
output = {}
for vert in range(24):
for hrz in range(80):
output[(hrz,vert)]=' '
with open(infile,'r') as inf:
for vert,line in enumerate(inf.readlines()):
for hrz,chr in enumerate(line):
if chr == '\r' or chr == '\n':
chr = ' '
output[(hrz,vert)]=chr
return output
def sendimage(sock,img):
while len(img):
h,v = random.choice(list(img.keys()))
sock.sendto('\033[{};{}H{}'.format(v+1,h+1,img[(h,v)]),(UDP_IP,UDP_PORT))
del img[(h,v)]
time.sleep(.000001)
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
imgs = [text2img(img) for img in IMAGES]
while True:
for image in imgs:
sendimage(sock,dict(image))
time.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment