Skip to content

Instantly share code, notes, and snippets.

View davepape's full-sized avatar

Dave Pape davepape

View GitHub Profile
@davepape
davepape / alpha.py
Created October 8, 2013 03:51
basic alpha blending - a semi-transparent square blended over an opaque square
import time, math
from pyglet.gl import *
window = pyglet.window.Window()
class AlphaSquare:
def __init__(self, color):
self.xpos = 0
self.ypos = 0
self.color = color
@davepape
davepape / smoothalpha.py
Created October 8, 2013 03:55
smooth shading of alpha values - applies same RGB, but different alpha to the top and bottom of a square
import time, math
from pyglet.gl import *
window = pyglet.window.Window()
class AlphaSquare2:
def __init__(self, color1, color2):
self.xpos = 0
self.ypos = 0
colors = color1 + color1 + color2 + color2
@davepape
davepape / alphawheel.py
Created October 8, 2013 03:57
a soft-edged disc with alpha blending - the outer edge is fully transparent, while the center of the disc is opaque
import time, math
from pyglet.gl import *
window = pyglet.window.Window()
class Square:
def __init__(self, color):
self.color = color
self.vlist = pyglet.graphics.vertex_list(4, ('v2f', [-128,-128, 128,-128, -128,128, 128,128]))
def draw(self):
@davepape
davepape / fade.py
Created October 8, 2013 03:57
fading an object in and out by changing its alpha value over time
import time, math
from pyglet.gl import *
window = pyglet.window.Window()
class AlphaSquare:
def __init__(self, color):
self.xpos = 0
self.ypos = 0
self.color = color
@davepape
davepape / texalpha.py
Created October 8, 2013 03:58
using a texture map with an alpha channel to get a cut-out sprite
import time, math
from pyglet.gl import *
window = pyglet.window.Window()
class TexAlphaSquare:
def __init__(self, width, height, xpos, ypos, texturefile, color):
self.xpos = xpos
self.ypos = ypos
@davepape
davepape / filter.py
Created October 8, 2013 04:00
applying a "filter" - a square with different blending functions is drawn on top of the rendered scene. The first form fades everything in/out; the second multiplies everything by a color; the third creates a negative image
import time, math
from pyglet.gl import *
window = pyglet.window.Window()
class BlendFilter:
def __init__(self, srcFunc, destFunc, color):
self.srcFunc = srcFunc
self.destFunc = destFunc
@davepape
davepape / bounce.py
Created October 15, 2013 15:13
a bouncing ball, using a vector for movement
import sys, time, math
from pyglet.gl import *
from euclid import *
window = pyglet.window.Window(512,512)
quadric = gluNewQuadric()
ballPos = Vector2(256,256)
ballVel = Vector2(200,145)
@davepape
davepape / gravbounce.py
Created October 15, 2013 15:14
a bouncing ball, with gravitational acceleration pulling it downward
import sys, time, math
from pyglet.gl import *
from euclid import *
window = pyglet.window.Window(512,512)
quadric = gluNewQuadric()
ballPos = Vector2(256, 256)
ballVel = Vector2(80, 0)
@davepape
davepape / gravorbit.py
Last active December 25, 2015 14:48
simple solar system simulation - four objects moving with gravitation forces between them
import sys, time, math
from pyglet.gl import *
from euclid import *
GRAV_CONSTANT = 1
window = pyglet.window.Window(512,512)
def makeCircle(numPoints):
verts = [0,0]
@davepape
davepape / simplespring.py
Created October 15, 2013 15:17
basic spring simulation - two point masses connected by a spring
import sys, time, math
from pyglet.gl import *
from euclid import *
window = pyglet.window.Window(512,512)
point0 = Vector2(100, 240)
velocity0 = Vector2(0, 0)
mass0 = 1
point1 = Vector2(300, 240)