Skip to content

Instantly share code, notes, and snippets.

View davepape's full-sized avatar

Dave Pape davepape

View GitHub Profile
@davepape
davepape / fire.py
Created August 27, 2013 06:03
Basic particle system example
# fire.py
# by Dave Pape, for DMS 423
#
# Example particle system for a simple fire-like effect
# This code is intended as a trivial introduction to particle systems and
# graphics programming; it is NOT intended to be optimal; many values are
# hard-coded for simplicity.
#
# Requires: pyglet (http://www.pyglet.org/), euclid (https://code.google.com/p/pyeuclid/),
# and a texture image fireparticle.png
@davepape
davepape / clear.py
Created September 5, 2013 16:41
Minimal pyglet/OpenGL program
# clear.py
# by Dave Pape, for DMS 423
#
# Minimal pyglet/OpenGL program. Demonstration of the basic structure
# of such a program.
# Opens a window and clears it to all red.
# Load pyglet's OpenGL interface
from pyglet.gl import *
@davepape
davepape / triangle.py
Last active January 10, 2017 18:15
a triangle, using a pyglet vertex_list
# triangle.py
# by Dave Pape, for DMS 423
#
# Basic pyglet/OpenGL program to draw a single red triangle using a vertex list
from pyglet.gl import *
window = pyglet.window.Window()
# Create the vertex_list - 3 vertices, with 2-dimensional position data, and nothing else
@davepape
davepape / shapes.py
Created September 11, 2013 18:09
a couple simple shapes, using vertex_list
# shapes.py
# by Dave Pape, for DMS 423
#
# draw three shapes using two vertex lists - one vertex list for a yellow triangle,
# the other for a triangle strip and a line strip
from pyglet.gl import *
window = pyglet.window.Window()
@davepape
davepape / animtriangle.py
Created September 12, 2013 03:07
a triangle with one animated vertex
# animtriangle.py
# by Dave Pape, for DMS 423
#
# draws a triangle with one moving vertex
from pyglet.gl import *
window = pyglet.window.Window()
vlist = pyglet.graphics.vertex_list(3, ('v2f', [0,0, 400,50, 200,300]))
@davepape
davepape / interp.py
Created September 19, 2013 12:38
interpolation demo
# interp.py
# by Dave Pape, for DMS 423
#
# Moves two squares by interpolation of their X position
# The timing used in the interpolation is different -
# the red square moves purely linearly; the blue square
# uses a slow-in-slow-out
import time
from pyglet.gl import *
@davepape
davepape / circle.py
Created September 19, 2013 12:44
draw a circle
# circle.py
# by Dave Pape, for DMS 423
#
# draws a circle, where the points for the vertex list are computed at run-time
from math import *
from pyglet.gl import *
window = pyglet.window.Window()
@davepape
davepape / basicXform.py
Created September 24, 2013 12:45
basic OpenGL transformations
from pyglet.gl import *
window = pyglet.window.Window()
triangle = pyglet.graphics.vertex_list(3, ('v2f', [0,0, 40,0, 80,80]))
@window.event
def on_draw():
glClear(GL_COLOR_BUFFER_BIT)
glLoadIdentity()
@davepape
davepape / interactiveXform.py
Created September 24, 2013 12:46
interactive transformation - simple keyboard controls
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)
@davepape
davepape / animXform.py
Created September 24, 2013 12:46
animated transformation
from pyglet.gl import *
window = pyglet.window.Window(600,500)
triPosX = 10
triPosY = 10
triDX = 1
triDY = 1
triRot = 0
triangle = pyglet.graphics.vertex_list(3, ('v2f', [-50,-50, 50,-50, 0,50]))