from time import *
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from pygame import *
from random import *
A=random

s=X=Y=Z=M=F=L=R=J=E=H=W=0
C=[]
D=S=X=1
l=.2
m=.1
h=clock

def B(x):
	global H
	t=A()*S<1
	H+=1 
	if t | H>76: 
		t=H=1
	return t
	
init()
g=display
g.set_mode((640,480), 2|1<<30) 
glEnable(2929) 

while s!=27:
	a=int
	e=event.poll()
	r=e.type
	if r in [2,3]:
		t=r==2 
		s=e.key
		if s == 32: 
			J=t
		if s == 276: 
			L=t
		if s == 275: 
			R=t 

	E+=1
	if E>3:
		C=C[1:]
		E=0
		
	while len(C)<40:
		C+=[map(B,[0]*5)]
	
	if J:
		F+=.45-.44*M
		M=1

	Y+=F

	if D:
		if Y<=0:
			D=0
			M=1
			for i in C[a(E/4.+3.4):a(E/4.+8.5)]:
				if i[a(X)]: 
					D=1
					J=M=F=Y=0
	if Y<-20: break
	
	F-=.03*M

	X=max(0,min(X-(R-L)*m,4.99))

	S+=.01

	a=glTranslate
	b=glLoadIdentity
	c=glColor
	d=glMatrixMode
	e=.5
	f=glVertex
	P=h()
	d(5889) 
	b()
	gluPerspective(45, 1.3, m, 99)
	gluLookAt(2.5,3,-7,X/2+1.25,Y/2,Z,0,1,0)
	d(5888) 
	glClearColor(l,l,.7,0)
	glClear(16640) 
	glutInit()

	b()
	a(e,-l,-E*e-10)
	glScale(1,l,10)
	for i in C:
		glBegin(8) 
		for j in range(0,6):
			j-=e
			c(.8+A()/20,l+A()/15,0)
			f(j,-1,0)
			f(j,-1,l)
		glEnd()
		for j in i:
			c(m,.3,m)
			if j: glutSolidCube(1)
			a(1,0,0)
		a(-5,0,l)


	b()
	a(X,Y+l,0)
	c(0,0,0)
	glutSolidSphere(e,18,18)
	
	W+=1
	while h()-P<.05:
		0
	g.flip()

print "                      ",W


