import sys from OpenGL.GLUT import * from OpenGL.GLU import * from OpenGL.GL import * from random import random from copy import copy rule = {(1,1,1):0, (1,1,0):0, (1,0,1):0, (1,0,0):1, (0,1,1):1, (0,1,0):1, (0,0,1):1, (0,0,0):0} rule = {(1,1,1):0, (1,1,0):1, (1,0,1):1, (1,0,0):1, (0,1,1):1, (0,1,0):1, (0,0,1):1, (0,0,0):0} row = [0 for i in xrange(500)] next_row = [0 for i in xrange(500)] row[250] = 1 j = -2 def update_rows( ): global row, next_row for i in xrange(len(row)): try: next_row[i] = rule[(row[i-1], row[i], row[i+1])] except IndexError: if i == len(row)-1: next_row[i] = rule[(row[i-1], row[i], 0)] elif i == 0: next_row[i] = rule[(0, row[i], row[i+1])] for i in xrange(len(row)): row[i] = next_row[i] def display( ): global j # glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_POINTS) for i in xrange(500): if row[i] == 1: glColor(0.2,1,0.5) else: glColor(0.1,0,0) glVertex(2.5-i*0.01, -j) update_rows( ) glEnd() glutSwapBuffers( ) j += 0.01 def idle( ): glutPostRedisplay( ) def init( ): glClear(0) glColor(1,1,1) glMatrixMode(GL_PROJECTION) glLoadIdentity( ) gluOrtho2D(-2, 2, -2, 2) glPointSize(2) if __name__ == "__main__": glutInit(sys.argv) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) glutInitWindowSize(400, 400) glutInitWindowPosition(0,0) glutCreateWindow("rule30") glutDisplayFunc(display) glutIdleFunc(idle) init( ) glutMainLoop( )