# This program receives data from the 'netserve' XMMS plugin, and draws it # as a simple line plot import sys, time, math, os, socket, string, struct from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * from dmsgl import * startdir = os.getcwd() sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(('', 10000)) windowWidth, windowHeight = 400, 400 camera = OrthoCamera(left=0, right=0.3, bottom=0, top=1) heights = [] def draw(): glClear(GL_COLOR_BUFFER_BIT) Color.Red.apply() camera.apply() glBegin(GL_LINE_STRIP) index = 0 for v in heights: glVertex2f(float(index)/len(heights), (v+16000)/32000.0) index += 1 glEnd() glutSwapBuffers() def keyboard(key, x, y): if key == chr(27): sys.exit(0) def update(): global heights buf = sock.recv(2048) heights = struct.unpack('h'*256, buf[0:512]) glutPostRedisplay() glutInit([]) glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE) glutInitWindowSize(windowWidth, windowHeight) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutIdleFunc(update) os.chdir(startdir) glutMainLoop()