Skip to content

Instantly share code, notes, and snippets.

View davepape's full-sized avatar

Dave Pape davepape

View GitHub Profile
@davepape
davepape / swing.py
Created October 15, 2013 15:18
swinging pendulum - a point mass affected by gravity plus spring force; other point mass is fixed in place
import sys, time, math
from pyglet.gl import *
from euclid import *
from Spring import *
window = pyglet.window.Window(512,512)
GravityAccel = Vector3(0, -98, 0)
AirDrag = 2
BounceCoeff = 0.8
@davepape
davepape / Spring.py
Created October 15, 2013 15:19
module defining classes for a point mass and a simple spring
from pyglet.gl import *
from euclid import *
class PointMass:
def __init__(self, position, velocity, mass):
self.position = position.copy()
self.velocity = velocity.copy()
self.mass = mass
self.force = Vector3(0, 0, 0)
self.mobile = True
@davepape
davepape / rope.py
Created October 15, 2013 15:19
a rope - sequence of point masses connected by springs. Uses the module Spring.py.
import sys, time, math
from pyglet.gl import *
from euclid import *
from Spring import *
window = pyglet.window.Window(512,512)
GravityAccel = Vector3(0, -98, 0)
AirDrag = 2
BounceCoeff = 0.8
@davepape
davepape / sprite.py
Created October 22, 2013 13:46
a sprite moving under keyboard control, with basic collision detection
import sys, time, math, random
from pyglet.gl import *
window = pyglet.window.Window()
keys = pyglet.window.key.KeyStateHandler()
window.push_handlers(keys)
class BoundCircle:
def __init__(self, center, radius):
@davepape
davepape / glmandelbrot.py
Created October 22, 2013 14:12
compute a Mandelbrot set and draw it using OpenGL points
import sys, random
from pyglet.gl import *
width = 400
height = 400
singlebuffered = pyglet.gl.Config(double_buffer=False)
window = pyglet.window.Window(width,height,config=singlebuffered)
@davepape
davepape / mountain1d.py
Created October 22, 2013 15:02
Fractal mountain outline using midpoint subdivision
import sys, random
from pyglet.gl import *
window = pyglet.window.Window(500,500)
seed = int(random.uniform(0,10000))
if len(sys.argv) > 1:
seed = int(sys.argv[1])
def generateHeights(level):
@davepape
davepape / zap.py
Created October 24, 2013 15:28
Uses the 1d fractal mountain code to generate a constantly changing electrical 'zap'. Also plays a looping sound effect.
import sys, random
from pyglet.gl import *
window = pyglet.window.Window()
tex = pyglet.image.load('glow.png').get_texture()
sound = pyglet.media.load('zap.wav')
player = pyglet.media.Player()
player.queue(sound)
player.eos_action = player.EOS_LOOP
@davepape
davepape / gazmap.py
Created November 5, 2013 19:43
Plots points from the US Census's 2000 gazetteer as a simple equirectangular (latitude/longitude) map.
from pyglet.gl import *
f = open('places2k.txt')
lines = f.readlines()
f.close()
verts = []
for l in lines:
pop = int(l[73:82])
@davepape
davepape / map3d.py
Last active December 27, 2015 12:19
Plots points from the US Census's 2000 gazetteer on a sphere.
from pyglet.gl import *
from math import *
f = open('places2k.txt')
lines = f.readlines()
f.close()
verts = []
for l in lines:
@davepape
davepape / globe.py
Last active June 24, 2022 09:33
Draws a sphere with a texture.
from pyglet.gl import *
from math import *
tex = pyglet.image.load('biosphere.png').get_texture()
step = 10
vlists = []
for lat in range(-90,90,step):
verts = []