2010-11-16 20:27:22 +01:00
|
|
|
# Client program
|
|
|
|
|
|
|
|
from socket import *
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
from math import *
|
|
|
|
|
|
|
|
# Set the socket parameters
|
|
|
|
local_port = 5000
|
|
|
|
remote_port = 4321
|
|
|
|
|
|
|
|
# TODO: autodetect interface address for remote application
|
|
|
|
outgoing_if = "127.0.0.1"
|
|
|
|
remote_host = "127.0.0.1"
|
|
|
|
|
|
|
|
# udp is the default for DGRAM
|
|
|
|
UDPSock = socket(AF_INET, SOCK_DGRAM)
|
2010-11-22 17:47:32 +01:00
|
|
|
|
|
|
|
# we MUST bind, otherwise python will choose a different port for each
|
|
|
|
# connection
|
2010-11-16 20:27:22 +01:00
|
|
|
UDPSock.bind((outgoing_if, local_port))
|
|
|
|
|
|
|
|
# we will not use connections so we can keep working even if the server
|
|
|
|
# goes down or refuses connection
|
|
|
|
#UDPSock.connect((remote_host, remote_port))
|
|
|
|
|
|
|
|
segments = open('segments','r')
|
|
|
|
|
2010-11-22 17:41:21 +01:00
|
|
|
alpha = chr(125)
|
2010-11-16 20:27:22 +01:00
|
|
|
|
2010-11-17 12:38:53 +01:00
|
|
|
z_buffer = chr(1) + "\n"
|
2010-11-17 14:50:21 +01:00
|
|
|
|
2010-11-16 20:27:22 +01:00
|
|
|
width = 7
|
|
|
|
height = 12
|
|
|
|
|
2010-11-17 14:50:21 +01:00
|
|
|
segments = 8
|
|
|
|
segwidth = 12
|
|
|
|
segchannels = 4
|
|
|
|
|
2010-11-17 12:38:53 +01:00
|
|
|
sleeptime = 0.03
|
2010-11-16 20:27:22 +01:00
|
|
|
t = 0
|
2010-11-17 15:38:40 +01:00
|
|
|
|
|
|
|
#timer will hold the elapsed time in seconds
|
2010-11-17 12:38:53 +01:00
|
|
|
frequency = 2*pi/200
|
|
|
|
|
2010-11-16 20:27:22 +01:00
|
|
|
while (1):
|
|
|
|
#zero out the data buffer
|
|
|
|
data = z_buffer
|
|
|
|
for i in range(0,width):
|
|
|
|
for j in range(0,height):
|
2010-11-17 12:38:53 +01:00
|
|
|
pixel = fabs(sin(2*pi*(float(i)/width)+t*frequency)*sin(2*pi*(float(j)/height)+t*frequency))
|
2010-11-22 17:47:32 +01:00
|
|
|
data = data + chr(int(255*pixel)) + alpha
|
2010-11-16 20:27:22 +01:00
|
|
|
data = data + "\n"
|
2010-11-17 14:50:21 +01:00
|
|
|
for i in range(0,segwidth):
|
|
|
|
for j in range(0,segments):
|
|
|
|
for a in range(0,segchannels):
|
2010-11-22 17:47:32 +01:00
|
|
|
data += chr(255)
|
2010-11-17 14:50:21 +01:00
|
|
|
data += "\n"
|
2010-11-16 20:27:22 +01:00
|
|
|
t+=1
|
|
|
|
if not data:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
UDPSock.sendto(data,(remote_host,remote_port))
|
|
|
|
time.sleep(sleeptime)
|
|
|
|
|
|
|
|
UDPSock.close()
|