Esempio n. 1
0
class SphereCubes:
    def __init__(self):
        self.cubes = []

        alpha_inc = math.pi / 20.0
        theta_inc = math.pi / 20.0
        pip2 = math.pi / 2.0
        pi2 = math.pi * 2

        for alpha in frange(-pip2, pip2, alpha_inc):
            for theta in frange(0, pi2, theta_inc):
                nx = math.cos(alpha) * math.sin(theta) * 6.0
                ny = math.cos(alpha) * math.cos(theta) * 6.0
                nz = -math.sin(alpha) * 6.0
                self.cubes.append(
                    MeshCube(0.275, 0.275, 0.275, tx=nx, ty=ny, tz=nz))

        self.shader = Shader("media/shaders/spherecubes.vert",
                             "media/shaders/spherecubes.frag",
                             isFile=True)

    def draw(self):
        self.shader.bind()
        self.shader["lightPos"] = [1, 1, 0]

        for cube in self.cubes:
            cube.draw()

        self.shader.release()

    def on_beat(self, dt):
        pass

    def update(self, dt):
        pass
Esempio n. 2
0
class Overlay:
	def __init__(self):
		self.quad = MeshQuad()
		self.texture = Texture("media/textures/border4.png")
		#self.texture = Texture("media/textures/flare.png")
		self.shader = Shader("media/shaders/overlay.vert", "media/shaders/overlay.frag", isFile=True)

	def on_beat(self, dt):
		pass

	def update(self, dt):
		pass

	def draw(self):
		glEnable(GL_BLEND)
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
		#glBlendFunc(GL_SRC_ALPHA, GL_ONE)
		#glDepthMask(GL_FALSE)
		#glDisable(GL_DEPTH_TEST)
		self.texture.bind()
		self.shader.bind()
		glPushMatrix()
		glLoadIdentity()
		self.quad.draw()
		glPopMatrix()
		self.shader.release()
		self.texture.release()
		#glEnable(GL_DEPTH_TEST)
		#glDepthMask(GL_TRUE)
		glDisable(GL_BLEND)
Esempio n. 3
0
class SphereCubes:
	def __init__(self):
		self.cubes = []
		
		alpha_inc = math.pi / 20.0
		theta_inc = math.pi / 20.0
		pip2 = math.pi / 2.0
		pi2 = math.pi * 2

		for alpha in frange(-pip2, pip2, alpha_inc):
			for theta in frange(0, pi2, theta_inc):
				nx =  math.cos(alpha) * math.sin(theta) * 6.0;  
				ny =  math.cos(alpha) * math.cos(theta) * 6.0;
				nz = -math.sin(alpha) * 6.0
				self.cubes.append(MeshCube(0.275,0.275,0.275,tx=nx,ty=ny,tz=nz))

		self.shader = Shader("media/shaders/spherecubes.vert","media/shaders/spherecubes.frag",isFile=True)

	def draw(self):
		self.shader.bind()
		self.shader["lightPos"] = [1,1,0]
		
		for cube in self.cubes:
			cube.draw()

		self.shader.release()

	def on_beat(self, dt):
		pass

	def update(self, dt):
		pass
Esempio n. 4
0
class LightBeams:
    def __init__(self, n=512):
        self.texture = Texture("media/textures/flare3.png")
        #self.texture = Texture("media/textures/heart.tga")
        self.shader = Shader("media/shaders/beams.vert", fs=None, isFile=True)

        self.beams = []
        self.n = n

        for i in range(self.n):
            self.beams.append([
                random.random() * 10,
                random.random() * 10,
                random.random() * 10
            ])

        self.beamlistid = glGenLists(1)
        glNewList(self.beamlistid, GL_COMPILE)
        glBegin(GL_POINTS)
        for i in range(self.n):
            glVertex3f(self.beams[i][0], self.beams[i][1], self.beams[i][2])
        glEnd()
        glEndList()

        self.dt = 0

    def on_beat(self, beat):
        pass

    def update(self, dt):
        self.dt += dt

    def draw(self):
        #glColor4f(0.9,0.1,0.1,1)
        self.texture.bind()
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE)

        glEnable(GL_POINT_SPRITE)
        glPointSize(60.0)
        glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE)
        #glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, 60.0);
        #glPointParameterf(GL_POINT_SIZE_MIN, 30.0);
        #glPointParameterf(GL_POINT_SIZE_MAX, 40.0);

        glDepthMask(GL_FALSE)
        glPushMatrix()
        glTranslatef(-5, -5, -5)
        self.shader.bind()
        self.shader["time"] = float(self.dt)
        glCallList(self.beamlistid)
        self.shader.release()
        glPopMatrix()
        glDepthMask(GL_TRUE)
        glDisable(GL_POINT_SPRITE)
        glDisable(GL_BLEND)
        self.texture.release()
        glColor4f(1, 1, 1, 1)

        self.beat = False
Esempio n. 5
0
class LightBeams:
	def __init__(self,n=512):
		self.texture = Texture("media/textures/flare3.png")
		#self.texture = Texture("media/textures/heart.tga")
		self.shader = Shader("media/shaders/beams.vert",fs=None,isFile=True)

		self.beams = []
		self.n = n

		for i in range(self.n):
			self.beams.append([random.random() * 10, random.random() * 10, random.random() * 10])

		self.beamlistid = glGenLists(1)
		glNewList(self.beamlistid, GL_COMPILE)
		glBegin(GL_POINTS)
		for i in range(self.n):
			glVertex3f(	self.beams[i][0],
						self.beams[i][1],
						self.beams[i][2] )
		glEnd()
		glEndList()

		self.dt = 0

	def on_beat(self, beat):
		pass

	def update(self, dt):
		self.dt += dt
		
	def draw(self):
		#glColor4f(0.9,0.1,0.1,1)
		self.texture.bind()
		glEnable(GL_BLEND)
		glBlendFunc(GL_SRC_ALPHA, GL_ONE)

		glEnable(GL_POINT_SPRITE)
		glPointSize(60.0)
		glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
		#glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, 60.0);
		#glPointParameterf(GL_POINT_SIZE_MIN, 30.0);
		#glPointParameterf(GL_POINT_SIZE_MAX, 40.0);
		
		glDepthMask(GL_FALSE)
		glPushMatrix()
		glTranslatef(-5,-5,-5)
		self.shader.bind()
		self.shader["time"] = float(self.dt)
		glCallList(self.beamlistid)
		self.shader.release()
		glPopMatrix()
		glDepthMask(GL_TRUE)
		glDisable(GL_POINT_SPRITE)
		glDisable(GL_BLEND)
		self.texture.release()
		glColor4f(1,1,1,1)

		self.beat = False
Esempio n. 6
0
class PostProcess:
    def __init__(self, w=1024, h=1024):
        self.quad = MeshQuad()
        self.shader = Shader("media/shaders/postprocess.vert",
                             "media/shaders/postprocess.frag",
                             isFile=True)
        self.rt = RenderTarget(w, h, multisample=True)
        self.dt = 0
        self.mode = 0
        self.texture = Texture("media/textures/gradient.png")

    def on_beat(self, beat):
        pass

    def switch(self, n):
        self.mode = n

    def current(self):
        return self.mode

    def num(self):
        return 6

    def bind(self):
        if self.mode == 0:
            return

        self.rt.bind()

    def release(self):
        if self.mode == 0:
            return

        self.rt.release()

    def update(self, dt):
        self.dt += dt

    def draw(self):
        if self.mode == 0:
            return

        self.rt.texture.bind()
        self.shader.bind()
        self.shader["time"] = float(self.dt)
        self.shader["rt_w"] = float(self.rt.w)
        self.shader["rt_h"] = float(self.rt.h)
        self.shader["mode"] = float(self.mode)
        self.shader["texture2"] = int(1)
        self.texture.bind(1)
        self.quad.draw()
        self.texture.release()
        self.shader.release()
        self.rt.texture.release()
Esempio n. 7
0
class PostProcess:
	def __init__(self, w=1024, h=1024):
		self.quad = MeshQuad()
		self.shader = Shader("media/shaders/postprocess.vert", "media/shaders/postprocess.frag", isFile=True)
		self.rt = RenderTarget(w,h,multisample=True)
		self.dt = 0
		self.mode = 0
		self.texture = Texture("media/textures/gradient.png")

	def on_beat(self, beat):
		pass

	def switch(self, n):
		self.mode = n

	def current(self):
		return self.mode

	def num(self):
		return 6

	def bind(self):
		if self.mode == 0:
			return

		self.rt.bind()

	def release(self):
		if self.mode == 0:
			return

		self.rt.release()

	def update(self, dt):
		self.dt += dt

	def draw(self):
		if self.mode == 0:
			return

		self.rt.texture.bind()
		self.shader.bind()
		self.shader["time"] = float(self.dt)
		self.shader["rt_w"] = float(self.rt.w)
		self.shader["rt_h"] = float(self.rt.h)
		self.shader["mode"] = float(self.mode)
		self.shader["texture2"] = int(1)
		self.texture.bind(1)
		self.quad.draw()
		self.texture.release()
		self.shader.release()
		self.rt.texture.release()
Esempio n. 8
0
class Gears:
    def __init__(self, r=10):
        self.cubes = []

        for i in range(100):
            nx = math.sin(180 * i)
            ny = math.cos(180 * i)
            nz = 0
            self.cubes.append(MeshCube(0.02, 0.02, 0.02, tx=nx, ty=ny, tz=nz))

        self.dt = 0
        self.beat_dt = 0
        self.r = 0
        self.r2 = 0

        self.shader = Shader("media/shaders/gears.vert",
                             "media/shaders/gears.frag",
                             isFile=True)

    def on_beat(self, beat):
        self.beat_dt += beat.confidence

    def update(self, dt):
        self.r += dt * 60
        self.r2 -= dt * 80
        self.dt += dt

    def draw(self):
        self.shader.bind()
        self.shader["lightPos"] = [5, 2, 0]
        self.shader["time"] = float(self.dt)
        self.shader["beat"] = float(self.beat_dt)
        glPushMatrix()
        glScalef(2.8, 2.8, 2.8)
        glRotatef(self.r, 1, 1, 1)
        for c in self.cubes:
            c.draw()
        glPopMatrix()
        glPushMatrix()
        glScalef(2.5, 2.5, 2.5)
        glRotatef(self.r2, 1, 1, 1)
        for c in self.cubes:
            c.draw()
        glPopMatrix()
        self.shader.release()
Esempio n. 9
0
class Gears:
	def __init__(self,r=10):
		self.cubes = []

		for i in range(100):
			nx = math.sin(180*i)
			ny = math.cos(180*i)
			nz = 0
			self.cubes.append(MeshCube(0.02,0.02,0.02,tx=nx,ty=ny,tz=nz))

		self.dt = 0
		self.beat_dt = 0
		self.r = 0
		self.r2=0

		self.shader = Shader("media/shaders/gears.vert","media/shaders/gears.frag",isFile=True)

	def on_beat(self, beat):
		self.beat_dt += beat.confidence

	def update(self, dt):
		self.r += dt * 60
		self.r2-= dt * 80
		self.dt+= dt

	def draw(self):
		self.shader.bind()
		self.shader["lightPos"] = [5,2,0]
		self.shader["time"] = float(self.dt)
		self.shader["beat"] = float(self.beat_dt)
		glPushMatrix()
		glScalef(2.8,2.8,2.8)
		glRotatef(self.r, 1, 1, 1)
		for c in self.cubes:
			c.draw()
		glPopMatrix()
		glPushMatrix()
		glScalef(2.5,2.5,2.5)
		glRotatef(self.r2, 1, 1, 1)
		for c in self.cubes:
			c.draw()
		glPopMatrix()
		self.shader.release()
Esempio n. 10
0
class Heart:
	def __init__(self):
		self.heart = MeshObj("media/geometry/heart.obj")
		#self.heart = MeshObj("media/geometry/apricot.obj")
		self.shader = Shader("media/shaders/heart.vert","media/shaders/heart.frag",isFile=True)
		self.shader2 = Shader("media/shaders/heart.vert",None,isFile=True)
		
		self.dt = 0
		self.beat = 0

	def on_beat(self, beat):
		self.beat += (beat.confidence / 2)
		self.dt += (beat.confidence / 3)
	
	def update(self, dt):
		self.beat += dt
		self.dt += dt

	def draw(self):
		glPushMatrix()
		glTranslatef(0,-2,0)
		glRotatef(math.sin(self.beat)*160, 0, 1, 0)

		self.shader.bind()
		self.shader["lightPos"] = [10,10,0]
		self.shader["time"] = float(self.dt)
		self.shader["beat"] = float(self.beat)
		self.heart.draw()
		self.shader.release()

		self.shader2.bind()
		self.shader2["time"] = float(self.dt)
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
		glLineWidth(2.0)
		self.heart.draw()
		glLineWidth(1.0)
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
		self.shader2.release()

		glPopMatrix()
Esempio n. 11
0
class Heart:
    def __init__(self):
        self.heart = MeshObj("media/geometry/heart.obj")
        # self.heart = MeshObj("media/geometry/apricot.obj")
        self.shader = Shader("media/shaders/heart.vert", "media/shaders/heart.frag", isFile=True)
        self.shader2 = Shader("media/shaders/heart.vert", None, isFile=True)

        self.dt = 0
        self.beat = 0

    def on_beat(self, beat):
        self.beat += beat.confidence / 2
        self.dt += beat.confidence / 3

    def update(self, dt):
        self.beat += dt
        self.dt += dt

    def draw(self):
        glPushMatrix()
        glTranslatef(0, -2, 0)
        glRotatef(math.sin(self.beat) * 160, 0, 1, 0)

        self.shader.bind()
        self.shader["lightPos"] = [10, 10, 0]
        self.shader["time"] = float(self.dt)
        self.shader["beat"] = float(self.beat)
        self.heart.draw()
        self.shader.release()

        self.shader2.bind()
        self.shader2["time"] = float(self.dt)
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
        glLineWidth(2.0)
        self.heart.draw()
        glLineWidth(1.0)
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        self.shader2.release()

        glPopMatrix()
Esempio n. 12
0
class FlowerGardens:
	def __init__(self, n=32, f=6):
		self.n = n # number of floating platforms (a.k.a gardens)
		self.f = f # maximum number of flowers per platform

		self.platforms = []
		self.flowers = []

		for i in range(self.n):
			nx = (random.random() * 5) - random.random() * 1
			ny = (random.random() * 5)
			nz = (random.random() * 5) - random.random() * 1
			self.platforms.append(MeshCube(0.1,0.02,0.1,tx=nx,ty=ny,tz=nz))
			self.flowers.extend(self.create_flowers(nx, ny+0.02, nz))

		self.flowertexture = Texture("media/textures/flare2.png")

		self.flowerlistid = glGenLists(1)
		glNewList(self.flowerlistid, GL_COMPILE)
		glColor4f(0.0,0.4,0.8,1)
		for f in self.flowers:
			i = 0
			glLineWidth(1.5)
			glBegin(GL_LINE_STRIP)
			for s in range(f['n']):
				glNormal3f(f['n'],float(i),float(f['d']))
				glVertex3f(f['x'],f['y']+(s*0.1),f['z'])
				i+=1
			glEnd()
		glColor4f(1,1,1,1)
		glEndList()

		self.flowerlistid2 = glGenLists(1)
		glNewList(self.flowerlistid2, GL_COMPILE)
		glColor4f(1,1,1,1)
		for f in self.flowers:
			i = 0
			glPointSize(20.0)
			glBegin(GL_POINTS)
			for s in range(f['n']):
				glNormal3f(f['n'],float(i),float(f['d']))
				glVertex3f(f['x'],f['y']+(s*0.1),f['z'])					
				i+=1
			glEnd()
		glEndList()

		self.platformshader = Shader("media/shaders/spherecubes.vert", "media/shaders/spherecubes.frag", isFile=True)
		self.flowershader = Shader("media/shaders/flowers.vert", None, isFile=True)

		self.dt = 0

	def create_flowers(self, x, y, z):
		flowers = []
		dx = x
		dy = y
		dz = z
		
		dn = random.random() * self.f
		while dn < 3:
			dn = random.random() * self.f

		d = random.random() - 0.5

		flowers.append({'x':dx-0.05,'y':dy,'z':dz-0.05,'n':int(dn),'d':d})

		dn = random.random() * self.f
		while dn < 3:
			dn = random.random() * self.f

		d = random.random() - 0.5

		flowers.append({'x':dx-0.05,'y':dy,'z':dz+0.05,'n':int(dn),'d':d})

		dn = random.random() * self.f
		while dn < 3:
			dn = random.random() * self.f

		d = random.random() - 0.5

		flowers.append({'x':dx,'y':dy,'z':dz,'n':int(dn),'d':d})
		
		dn = random.random() * self.f
		while dn < 3:
			dn = random.random() * self.f

		d = random.random() - 0.5

		flowers.append({'x':dx+0.05,'y':dy,'z':dz-0.05,'n':int(dn),'d':d})
		
		dn = random.random() * self.f
		while dn < 3:
			dn = random.random() * self.f

		d = random.random() - 0.5

		flowers.append({'x':dx+0.05,'y':dy,'z':dz+0.05,'n':int(dn),'d':d})

		return flowers

	def on_beat(self, beat):
		self.dt += (beat.confidence / 3)

	def update(self, dt):
		self.dt += dt

	def draw(self):
		glPushMatrix()
		glTranslatef(-2,-3,-2)

		self.platformshader.bind()
		self.platformshader["lightPos"] = [10,10,0]

		for p in self.platforms:
			p.draw()

		self.platformshader.release()

		self.flowershader.bind()
		self.flowershader["time"] = float(self.dt)

		glCallList(self.flowerlistid)
	
		glEnable(GL_POINT_SPRITE)
		glPointSize(50.0)
		glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);

		glEnable(GL_BLEND)
		glBlendFunc(GL_SRC_ALPHA, GL_ONE)
		glDepthMask(GL_FALSE)
		self.flowertexture.bind()
		glCallList(self.flowerlistid2)
		self.flowertexture.release()
		glDepthMask(GL_TRUE)
		glDisable(GL_BLEND)
		glDisable(GL_POINT_SPRITE)

		self.flowershader.release()

		glPopMatrix()
Esempio n. 13
0
class FlowerGardens:
    def __init__(self, n=32, f=6):
        self.n = n  # number of floating platforms (a.k.a gardens)
        self.f = f  # maximum number of flowers per platform

        self.platforms = []
        self.flowers = []

        for i in range(self.n):
            nx = (random.random() * 5) - random.random() * 1
            ny = (random.random() * 5)
            nz = (random.random() * 5) - random.random() * 1
            self.platforms.append(MeshCube(0.1, 0.02, 0.1, tx=nx, ty=ny,
                                           tz=nz))
            self.flowers.extend(self.create_flowers(nx, ny + 0.02, nz))

        self.flowertexture = Texture("media/textures/flare2.png")

        self.flowerlistid = glGenLists(1)
        glNewList(self.flowerlistid, GL_COMPILE)
        glColor4f(0.0, 0.4, 0.8, 1)
        for f in self.flowers:
            i = 0
            glLineWidth(1.5)
            glBegin(GL_LINE_STRIP)
            for s in range(f['n']):
                glNormal3f(f['n'], float(i), float(f['d']))
                glVertex3f(f['x'], f['y'] + (s * 0.1), f['z'])
                i += 1
            glEnd()
        glColor4f(1, 1, 1, 1)
        glEndList()

        self.flowerlistid2 = glGenLists(1)
        glNewList(self.flowerlistid2, GL_COMPILE)
        glColor4f(1, 1, 1, 1)
        for f in self.flowers:
            i = 0
            glPointSize(20.0)
            glBegin(GL_POINTS)
            for s in range(f['n']):
                glNormal3f(f['n'], float(i), float(f['d']))
                glVertex3f(f['x'], f['y'] + (s * 0.1), f['z'])
                i += 1
            glEnd()
        glEndList()

        self.platformshader = Shader("media/shaders/spherecubes.vert",
                                     "media/shaders/spherecubes.frag",
                                     isFile=True)
        self.flowershader = Shader("media/shaders/flowers.vert",
                                   None,
                                   isFile=True)

        self.dt = 0

    def create_flowers(self, x, y, z):
        flowers = []
        dx = x
        dy = y
        dz = z

        dn = random.random() * self.f
        while dn < 3:
            dn = random.random() * self.f

        d = random.random() - 0.5

        flowers.append({
            'x': dx - 0.05,
            'y': dy,
            'z': dz - 0.05,
            'n': int(dn),
            'd': d
        })

        dn = random.random() * self.f
        while dn < 3:
            dn = random.random() * self.f

        d = random.random() - 0.5

        flowers.append({
            'x': dx - 0.05,
            'y': dy,
            'z': dz + 0.05,
            'n': int(dn),
            'd': d
        })

        dn = random.random() * self.f
        while dn < 3:
            dn = random.random() * self.f

        d = random.random() - 0.5

        flowers.append({'x': dx, 'y': dy, 'z': dz, 'n': int(dn), 'd': d})

        dn = random.random() * self.f
        while dn < 3:
            dn = random.random() * self.f

        d = random.random() - 0.5

        flowers.append({
            'x': dx + 0.05,
            'y': dy,
            'z': dz - 0.05,
            'n': int(dn),
            'd': d
        })

        dn = random.random() * self.f
        while dn < 3:
            dn = random.random() * self.f

        d = random.random() - 0.5

        flowers.append({
            'x': dx + 0.05,
            'y': dy,
            'z': dz + 0.05,
            'n': int(dn),
            'd': d
        })

        return flowers

    def on_beat(self, beat):
        self.dt += (beat.confidence / 3)

    def update(self, dt):
        self.dt += dt

    def draw(self):
        glPushMatrix()
        glTranslatef(-2, -3, -2)

        self.platformshader.bind()
        self.platformshader["lightPos"] = [10, 10, 0]

        for p in self.platforms:
            p.draw()

        self.platformshader.release()

        self.flowershader.bind()
        self.flowershader["time"] = float(self.dt)

        glCallList(self.flowerlistid)

        glEnable(GL_POINT_SPRITE)
        glPointSize(50.0)
        glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE)

        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE)
        glDepthMask(GL_FALSE)
        self.flowertexture.bind()
        glCallList(self.flowerlistid2)
        self.flowertexture.release()
        glDepthMask(GL_TRUE)
        glDisable(GL_BLEND)
        glDisable(GL_POINT_SPRITE)

        self.flowershader.release()

        glPopMatrix()