pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Python pastebin - collaborative debugging tool View Help


Posted by phlyingpenguin on Mon 29 Sep 20:37
report abuse | View followups from phlyingpenguin | download | new post

  1. from OpenGL.GL import *
  2. from OpenGL.GLU import *
  3. from OpenGL.GLUT import *
  4.  
  5. """
  6. This is a converted version of the Homework 4 program from C to Python.
  7. """
  8.  
  9. class HW4:
  10.         year = 0
  11.         day = 0
  12.  
  13.         def display(self):
  14.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  15.                 glPushMatrix()
  16.                 glColor3f(1.0, 1.0, 0.0)
  17.                 glutSolidSphere(1.0, 20, 16)
  18.                 glRotatef(self.year, 0.0, 1.0, 0.0)
  19.                 glTranslatef(2.0, 0.0, 0.0)
  20.                 glRotatef(self.day, 0.0, 1.0, 0.0)
  21.                 glColor3f(0.0, 0.0, 1.0)
  22.                 glutWireSphere(0.2, 10, 8)
  23.                 glPopMatrix()
  24.                 glutSwapBuffers()
  25.  
  26.         def reshape(self, w, h):
  27.                 glViewport(0,0,w,h)
  28.                 glMatrixMode(GL_PROJECTION)
  29.                 glLoadIdentity()
  30.                 if w <= h:
  31.                         glOrtho(-4.0, 4.0, -4.0 *  h /  w, 4.0 *  h /  w, -10.0, 10.0)
  32.                 else:
  33.                         glOrtho(-4.0 *  w /  h, 4.0 *  w /  h, -4.0, 4.0, -10.0, 10.0)
  34.                 glMatrixMode(GL_MODELVIEW)
  35.                 glLoadIdentity()
  36.  
  37.         def keyboard(self, key, x, y):
  38.                 if key == 'd': self.day=(self.day+10)%360
  39.                 if key == 'D' : self.day=(self.day-10)%360
  40.                 if key == 'y': self.year=(self.year+5)%360
  41.                 if key == 'Y': self.year=(self.year-5)%360
  42.                 if key == 'Q' or key == 'q': exit(0)
  43.                 glutPostRedisplay()
  44.  
  45.         def __init__(self):
  46.                 glutInit()
  47.                 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
  48.                 glutInitWindowSize(500, 500)
  49.                 glutInitWindowPosition(100,100)
  50.                 glutCreateWindow("HW4-2")
  51.                 glClearColor(0.0, 0.0, 0.0, 1.0)
  52.                 glutDisplayFunc(self.display)
  53.  
  54.                 glMatrixMode(GL_PROJECTION)
  55.                 glutReshapeFunc(self.reshape)
  56.                 glutKeyboardFunc(self.keyboard)
  57.                 glEnable(GL_DEPTH_TEST) #       /* Enable hidden-surface removal */
  58.  
  59.                 glutMainLoop()
  60.  
  61. HW4()

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post