Skip to content

Instantly share code, notes, and snippets.

View davepape's full-sized avatar

Dave Pape davepape

View GitHub Profile
@davepape
davepape / pushpop.py
Created September 24, 2013 12:47
glPushMatrix / glPopMatrix example
import sys, random, time, math
from pyglet.gl import *
window = pyglet.window.Window()
pos1 = [0,0]
pos2 = [-1, 0]
heading1 = 0
heading2 = 90
@davepape
davepape / pushpop2.py
Created September 24, 2013 12:48
another glPushMatrix/glPopMatrix example
import sys, random, time, math
from pyglet.gl import *
window = pyglet.window.Window(500,500)
pos1 = [0,0]
pos2 = [0, 0]
pos3 = [0, 0]
pos4 = [0, 0]
heading1 = 0
@davepape
davepape / car.py
Created September 24, 2013 12:49
simple animated car using push/pop matrix for hierarchical transformations
# This program draws a moving "car" with rotating wheels
# It demonstrates the use of the glPushMatrix and glPopMatrix to
# create a hierarchy of transformations.
from pyglet.gl import *
window = pyglet.window.Window(500,500)
angle = 0
carPosition = [100, 100, 0]
@davepape
davepape / animXform2.py
Created September 24, 2013 16:04
multiple bouncing triangles, using a simple class to hold the triangle data
from pyglet.gl import *
window = pyglet.window.Window(600,500)
class Triangle:
def __init__(self,x,y,dx,dy,rot):
self.posX = x
self.posY = y
self.dx = dx
self.dy = dy
@davepape
davepape / keyboard.py
Created September 26, 2013 15:01
keyboard input with pyglet
import sys
from math import *
from pyglet.gl import *
window = pyglet.window.Window()
class Circle:
def __init__(self,radius,r,g,b,x=0,y=0):
self.r = r
@davepape
davepape / mouse.py
Created September 26, 2013 15:02
mouse input with pyglet
import sys
from math import *
from pyglet.gl import *
window = pyglet.window.Window()
class Circle:
def __init__(self,radius,r,g,b,x=0,y=0):
self.r = r
self.g = g
@davepape
davepape / texturedSquare.py
Last active May 1, 2020 21:40
pyglet program drawing a single textured square. The square can be moved, rotated, and scaled, to demonstrate how the image remains attached to the shape.
import sys, time, math, os, random
from pyglet.gl import *
window = pyglet.window.Window()
keyboard = pyglet.window.key.KeyStateHandler()
window.push_handlers(keyboard)
class TexturedSquare:
def __init__(self, width, height, xpos, ypos, texturefile):
@davepape
davepape / texturedSquare_PIL.py
Last active June 17, 2021 13:57
Pyglet program to draw a single textured square - same as texturedSquare.py, except that it uses PIL (Python Image Library) to load the texture image, and then explicitly makes the OpenGL calls to create the texture (so that different tex parameters can be used).
import sys, time, math, os, random
import Image
from pyglet.gl import *
window = pyglet.window.Window()
keyboard = pyglet.window.key.KeyStateHandler()
window.push_handlers(keyboard)
def loadTexture(filename):
@davepape
davepape / disc.py
Last active December 24, 2015 14:19
Create a texture-mapped disc
import time
from math import *
from pyglet.gl import *
window = pyglet.window.Window()
keyboard = pyglet.window.key.KeyStateHandler()
window.push_handlers(keyboard)
def makeCircle(numPoints):
verts = [0,0]
@davepape
davepape / webtex.py
Created October 3, 2013 15:35
Create a texture map using an image grabbed from the web
import sys, time, math, os, random
import Image
import urllib2, StringIO
from pyglet.gl import *
window = pyglet.window.Window()
keyboard = pyglet.window.key.KeyStateHandler()
window.push_handlers(keyboard)
def getImageFromURL(url):