Created
          September 24, 2013 12:46 
        
      - 
      
 - 
        
Save davepape/6684168 to your computer and use it in GitHub Desktop.  
    interactive transformation - simple keyboard controls
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import sys, math, random | |
| from pyglet.gl import * | |
| window = pyglet.window.Window() | |
| points = [0,0] | |
| colors = [1,1,1] | |
| for i in range(0,41): | |
| angle = (i/40.0) * math.pi * 2 | |
| x,y = math.sin(angle), math.cos(angle) | |
| r,g,b = random.uniform(0,1), random.uniform(0,1), random.uniform(0,1) | |
| points += [x,y] | |
| colors += [r,g,b] | |
| wheel = pyglet.graphics.vertex_list(42, ('v2f', points), ('c3f', colors)) | |
| wheelScale = 25.0 | |
| wheelRot = 0 | |
| wheelTrans = [50,50] | |
| @window.event | |
| def on_draw(): | |
| glClear(GL_COLOR_BUFFER_BIT) | |
| glLoadIdentity() | |
| glTranslatef(wheelTrans[0], wheelTrans[1], 0) | |
| glRotatef(wheelRot, 0, 0, 1) | |
| glScalef(wheelScale, wheelScale, wheelScale) | |
| wheel.draw(GL_TRIANGLE_FAN) | |
| @window.event | |
| def on_key_press(key,modifiers): | |
| global wheelScale, wheelRot, wheelTrans | |
| if key == pyglet.window.key.ESCAPE: | |
| sys.exit(0) | |
| elif key == pyglet.window.key.W: | |
| wheelTrans[1] += 20 | |
| elif key == pyglet.window.key.A: | |
| wheelTrans[0] -= 20 | |
| elif key == pyglet.window.key.S: | |
| wheelTrans[1] -= 20 | |
| elif key == pyglet.window.key.D: | |
| wheelTrans[0] += 20 | |
| elif key == pyglet.window.key.UP: | |
| wheelScale += 2 | |
| elif key == pyglet.window.key.DOWN: | |
| wheelScale -= 2 | |
| elif key == pyglet.window.key.LEFT: | |
| wheelRot += 10 | |
| elif key == pyglet.window.key.RIGHT: | |
| wheelRot -= 10 | |
| pyglet.app.run() | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment