Skip to content

Commit

Permalink
Using 'import numpy as np'.
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzion committed Oct 11, 2010
1 parent 656e190 commit cb73028
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 74 deletions.
11 changes: 6 additions & 5 deletions src/AnimationPlayer.py
Expand Up @@ -29,7 +29,8 @@

from OpenGL.GL import *
# Array-based drawing
from numpy.core import array, float32

import numpy as np

from View import BackgroundLayer
import Log
Expand Down Expand Up @@ -149,19 +150,19 @@ def textureSetup(self):
vtxY = 1.0 - abs(self.winHeight-r*animHeight) / (float(self.winHeight))

# Vertices
animVtx = array([[-vtxX, vtxY],
animVtx = np.array([[-vtxX, vtxY],
[ vtxX, -vtxY],
[ vtxX, vtxY],
[-vtxX, vtxY],
[-vtxX, -vtxY],
[ vtxX, -vtxY]], dtype=float32)
[ vtxX, -vtxY]], dtype=np.float32)
# Texture coordinates
texCoord = array([[0.0, 1.0],
texCoord = np.array([[0.0, 1.0],
[1.0, 0.0],
[1.0, 1.0],
[0.0, 1.0],
[0.0, 0.0],
[1.0, 0.0]], dtype=float32)
[1.0, 0.0]], dtype=np.float32)

# Create a compiled OpenGL call list and do array-based drawing
# Could have used GL_QUADS but IIRC triangles are recommended
Expand Down
4 changes: 2 additions & 2 deletions src/Audio.py
Expand Up @@ -229,9 +229,9 @@ def fadeout(self, time):
def zeros(size):
return Numeric.zeros(size, typecode='s') #myfingershurt: typecode s = short = int16
else:
import numpy
import numpy as np
def zeros(size):
return numpy.zeros(size, dtype='h')
return np.zeros(size, dtype='h')

#stump: mic passthrough
class MicrophonePassthroughStream(Sound, Task):
Expand Down
6 changes: 3 additions & 3 deletions src/Font.py
Expand Up @@ -26,7 +26,7 @@
import cmgl
import sys
from Texture import Texture
from numpy.core import zeros, float32
import numpy as np

DEFAULT_SCALE = 0.002

Expand Down Expand Up @@ -89,8 +89,8 @@ def __init__(self, fileName, size, bold = False, italic = False, underline = Fal
self.font.set_italic(italic)
self.font.set_underline(underline)
self.stringsCache = Cache(256)
self.square_prim = zeros((4,2), dtype=float32)
self.square_tex = zeros((4,2), dtype=float32)
self.square_prim = np.zeros((4,2), dtype=np.float32)
self.square_tex = np.zeros((4,2), dtype=np.float32)

def getStringSize(self, s, scale = DEFAULT_SCALE):
"""
Expand Down
21 changes: 10 additions & 11 deletions src/GameEngine.py
Expand Up @@ -30,9 +30,8 @@

from OpenGL.GL import *
from OpenGL import __version__ as OpenGLVersion
import numpy
import numpy as np
from PIL import Image
from numpy.core import array, float32
import pygame
import gc
import os
Expand Down Expand Up @@ -485,7 +484,7 @@ def __init__(self, config = None):
Log.debug("Python version: " + sys.version.split(' ')[0])
Log.debug("Pygame version: " + str(pygame.version.ver) )
Log.debug("PyOpenGL version: " + OpenGLVersion)
Log.debug("Numpy version: " + numpy.__version__)
Log.debug("Numpy version: " + np.__version__)
Log.debug("PIL version: " + Image.VERSION)
Log.debug("sys.argv: " + repr(sys.argv))
Log.debug("os.name: " + os.name)
Expand Down Expand Up @@ -982,15 +981,15 @@ def draw3Dtex(self, image, vertex, texcoord, coord = None, scale = None, rot = N
glBlendFunc(GL_SRC_ALPHA, GL_ONE)

if len(color) == 4:
col_array = array([[color[0],color[1],color[2], color[3]],
col_array = np.array([[color[0],color[1],color[2], color[3]],
[color[0],color[1],color[2], color[3]],
[color[0],color[1],color[2], color[3]],
[color[0],color[1],color[2], color[3]]], dtype=float32)
[color[0],color[1],color[2], color[3]]], dtype=np.float32)
else:
col_array = array([[color[0],color[1],color[2], 1],
col_array = np.array([[color[0],color[1],color[2], 1],
[color[0],color[1],color[2], 1],
[color[0],color[1],color[2], 1],
[color[0],color[1],color[2], 1]], dtype=float32)
[color[0],color[1],color[2], 1]], dtype=np.float32)

glEnable(GL_TEXTURE_2D)
image.texture.bind()
Expand All @@ -1008,17 +1007,17 @@ def draw3Dtex(self, image, vertex, texcoord, coord = None, scale = None, rot = N
if depth == True:
glDepthMask(1)

triangVtx = array(
triangVtx = np.array(
[[ vertex[0], vertscale, vertex[1]],
[ vertex[2], vertscale, vertex[1]],
[ vertex[0], -vertscale, vertex[3]],
[ vertex[2], -vertscale, vertex[3]]], dtype=float32)
[ vertex[2], -vertscale, vertex[3]]], dtype=np.float32)

textriangVtx = array(
textriangVtx = np.array(
[[texcoord[0], texcoord[1]],
[texcoord[2], texcoord[1]],
[texcoord[0], texcoord[3]],
[texcoord[2], texcoord[3]]], dtype=float32)
[texcoord[2], texcoord[3]]], dtype=np.float32)

cmgl.drawArrays(GL_TRIANGLE_STRIP, vertices=triangVtx, colors=col_array, texcoords=textriangVtx)

Expand Down
4 changes: 2 additions & 2 deletions src/Microphone.py
Expand Up @@ -24,7 +24,7 @@
import Log
import Audio
import math
import numpy
import numpy as np

try:
import pyaudio
Expand Down Expand Up @@ -119,7 +119,7 @@ def run(self, ticks):
raise
if self.passthroughStream is not None:
self.passthroughQueue.append(chunk)
self.analyzer.input(numpy.frombuffer(chunk, dtype=numpy.float32))
self.analyzer.input(np.frombuffer(chunk, dtype=np.float32))
self.analyzer.process()
pk = self.analyzer.getPeak()
if self.detectTaps:
Expand Down
56 changes: 28 additions & 28 deletions src/Neck.py
Expand Up @@ -26,7 +26,7 @@
from Shader import shaders, mixColors

from OpenGL.GL import *
from numpy.core import array, float32
import numpy as np
import cmgl

#myfingershurt: needed for multi-OS file fetching
Expand Down Expand Up @@ -80,42 +80,42 @@ def __init__(self, engine, instrument, playerObj):
self.vis = 1

# evilynux - Neck color
self.board_col = array([[color[0],color[1],color[2], 0],
self.board_col = np.array([[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], self.vis],
[color[0],color[1],color[2], self.vis],
[color[0],color[1],color[2], self.vis],
[color[0],color[1],color[2], self.vis],
[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], 0]], dtype=float32)
[color[0],color[1],color[2], 0]], dtype=np.float32)

w = self.boardWidth
l = self.boardLength

# evilynux - Neck vertices
self.board_vtx = array([[-w / 2, 0, -2],
self.board_vtx = np.array([[-w / 2, 0, -2],
[w / 2, 0, -2],
[-w/ 2, 0, -1],
[w / 2, 0, -1],
[-w / 2, 0, l * .7],
[w / 2, 0, l * .7],
[-w / 2, 0, l],
[w / 2, 0, l]], dtype=float32)
[w / 2, 0, l]], dtype=np.float32)
# evilynux - Sidebars vertices
w += 0.15
self.sidebars_vtx = array([[-w / 2, 0, -2],
self.sidebars_vtx = np.array([[-w / 2, 0, -2],
[w / 2, 0, -2],
[-w/ 2, 0, -1],
[w / 2, 0, -1],
[-w / 2, 0, l * .7],
[w / 2, 0, l * .7],
[-w / 2, 0, l],
[w / 2, 0, l]], dtype=float32)
[w / 2, 0, l]], dtype=np.float32)

# evilynux - Just in case the type has became double, convert to float32
self.board_col = self.board_col.astype(float32)
self.board_vtx = self.board_vtx.astype(float32)
self.sidebars_vtx = self.sidebars_vtx.astype(float32)
self.board_col = self.board_col.astype(np.float32)
self.board_vtx = self.board_vtx.astype(np.float32)
self.sidebars_vtx = self.sidebars_vtx.astype(np.float32)

self.neckType = playerObj.neckType
if self.neckType == 0:
Expand Down Expand Up @@ -408,24 +408,24 @@ def project(beat):

glEnable(GL_TEXTURE_2D)

board_tex = array([[0.0, project(offset - 2 * self.beatsPerUnit)],
board_tex = np.array([[0.0, project(offset - 2 * self.beatsPerUnit)],
[1.0, project(offset - 2 * self.beatsPerUnit)],
[0.0, project(offset - 1 * self.beatsPerUnit)],
[1.0, project(offset - 1 * self.beatsPerUnit)],
[0.0, project(offset + l * self.beatsPerUnit * .7)],
[1.0, project(offset + l * self.beatsPerUnit * .7)],
[0.0, project(offset + l * self.beatsPerUnit)],
[1.0, project(offset + l * self.beatsPerUnit)]], dtype=float32)
[1.0, project(offset + l * self.beatsPerUnit)]], dtype=np.float32)

#must be seperate for neck flashing.
board_col = array([[color[0],color[1],color[2], 0],
board_col = np.array([[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], 0]], dtype=float32)
[color[0],color[1],color[2], 0]], dtype=np.float32)

if alpha == True:
glBlendFunc(GL_ONE, GL_ONE)
Expand Down Expand Up @@ -564,14 +564,14 @@ def project(beat):
else:
offset = (pos - self.lastBpmChange) / self.currentPeriod + self.baseBeat

track_tex = array([[0.0, project(offset - 2 * self.beatsPerUnit)],
track_tex = np.array([[0.0, project(offset - 2 * self.beatsPerUnit)],
[1.0, project(offset - 2 * self.beatsPerUnit)],
[0.0, project(offset - 1 * self.beatsPerUnit)],
[1.0, project(offset - 1 * self.beatsPerUnit)],
[0.0, project(offset + l * self.beatsPerUnit * .7)],
[1.0, project(offset + l * self.beatsPerUnit * .7)],
[0.0, project(offset + l * self.beatsPerUnit)],
[1.0, project(offset + l * self.beatsPerUnit)]], dtype=float32)
[1.0, project(offset + l * self.beatsPerUnit)]], dtype=np.float32)


glEnable(GL_TEXTURE_2D)
Expand All @@ -585,25 +585,25 @@ def project(beat):
self.centerLines.texture.bind()


track_vtx = array([[-w / 2, 0, -2+size],
track_vtx = np.array([[-w / 2, 0, -2+size],
[w / 2, 0, -2+size],
[-w / 2, 0, -1+size],
[w / 2, 0, -1+size],
[-w / 2, 0, l * .7],
[w / 2, 0, l * .7],
[-w / 2, 0, l],
[w / 2, 0, l]], dtype=float32)
[w / 2, 0, l]], dtype=np.float32)

if self.staticStrings: #MFH
color = (1,1,1)
track_col = array([[color[0],color[1],color[2], v],
track_col = np.array([[color[0],color[1],color[2], v],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], v],
[color[0],color[1],color[2], 0],
[color[0],color[1],color[2], 0]], dtype=float32)
[color[0],color[1],color[2], 0]], dtype=np.float32)
cmgl.drawArrays(GL_TRIANGLE_STRIP, vertices=track_vtx, colors=track_col, texcoords=track_tex)

else: #MFH: original moving strings
Expand All @@ -629,14 +629,14 @@ def project(beat):

c = (1,1,1)

board_tex = array([[0.0, project(offset - 2 * self.beatsPerUnit)],
board_tex = np.array([[0.0, project(offset - 2 * self.beatsPerUnit)],
[1.0, project(offset - 2 * self.beatsPerUnit)],
[0.0, project(offset - 1 * self.beatsPerUnit)],
[1.0, project(offset - 1 * self.beatsPerUnit)],
[0.0, project(offset + l * self.beatsPerUnit * .7)],
[1.0, project(offset + l * self.beatsPerUnit * .7)],
[0.0, project(offset + l * self.beatsPerUnit)],
[1.0, project(offset + l * self.beatsPerUnit)]], dtype=float32)
[1.0, project(offset + l * self.beatsPerUnit)]], dtype=np.float32)

glEnable(GL_TEXTURE_2D)
if self.theme == 2 and self.instrument.starPowerActive and self.oSideBars:
Expand Down Expand Up @@ -708,20 +708,20 @@ def drawBPM(self, visibility, song, pos):
sw = 0.1 #width
self.bpm_measure.texture.bind()

bpm_vtx = array([[-(w / 2), 0, z + sw],
bpm_vtx = np.array([[-(w / 2), 0, z + sw],
[-(w / 2), 0, z - sw],
[(w / 2), 0, z + sw],
[(w / 2), 0, z - sw]], dtype=float32)
[(w / 2), 0, z - sw]], dtype=np.float32)

bpm_tex = array([[0.0, 1.0],
bpm_tex = np.array([[0.0, 1.0],
[0.0, 0.0],
[1.0, 1.0],
[1.0, 0.0]], dtype=float32)
[1.0, 0.0]], dtype=np.float32)

bpm_col = array([[1, 1, 1, v],
bpm_col = np.array([[1, 1, 1, v],
[1, 1, 1, v],
[1, 1, 1, v],
[1, 1, 1, v]], dtype=float32)
[1, 1, 1, v]], dtype=np.float32)

cmgl.drawArrays(GL_TRIANGLE_STRIP, vertices=bpm_vtx, colors=bpm_col, texcoords=bpm_tex)

Expand Down
5 changes: 2 additions & 3 deletions src/Svg.py
Expand Up @@ -25,7 +25,6 @@
from OpenGL.GL import *

import numpy as np
from numpy.core import float32
import math
import cmgl

Expand Down Expand Up @@ -127,8 +126,8 @@ def __init__(self, context, ImgData):
self.createArrays()

def createArrays(self):
self.vtxArray = np.zeros((4,2), dtype=float32)
self.texArray = np.zeros((4,2), dtype=float32)
self.vtxArray = np.zeros((4,2), dtype=np.float32)
self.texArray = np.zeros((4,2), dtype=np.float32)

self.createVtx()
self.createTex()
Expand Down
14 changes: 7 additions & 7 deletions src/VideoPlayer.py
Expand Up @@ -47,7 +47,7 @@
from OpenGL.GL import *
from OpenGL.GLU import *
# Array-based drawing
from numpy.core import array, float32
import numpy as np

import cmgl

Expand Down Expand Up @@ -166,25 +166,25 @@ def textureSetup(self):
vtxY = 1.0 - abs(self.winHeight-r*self.vidHeight) / (float(self.winHeight))

# Vertices
videoVtx = array([[-vtxX, vtxY],
videoVtx = np.array([[-vtxX, vtxY],
[ vtxX, -vtxY],
[ vtxX, vtxY],
[-vtxX, vtxY],
[-vtxX, -vtxY],
[ vtxX, -vtxY]], dtype=float32)
backVtx = array([[-1.0, 1.0],
[ vtxX, -vtxY]], dtype=np.float32)
backVtx = np.array([[-1.0, 1.0],
[ 1.0, -1.0],
[ 1.0, 1.0],
[-1.0, 1.0],
[-1.0, -1.0],
[ 1.0, -1.0]], dtype=float32)
[ 1.0, -1.0]], dtype=np.float32)
# Texture coordinates
videoTex = array([[0.0, self.videoTex.size[1]],
videoTex = np.array([[0.0, self.videoTex.size[1]],
[self.videoTex.size[0], 0.0],
[self.videoTex.size[0], self.videoTex.size[1]],
[0.0, self.videoTex.size[1]],
[0.0, 0.0],
[self.videoTex.size[0], 0.0]], dtype=float32)
[self.videoTex.size[0], 0.0]], dtype=np.float32)

# Create a compiled OpenGL call list and do array-based drawing
# Could have used GL_QUADS but IIRC triangles are recommended
Expand Down

0 comments on commit cb73028

Please sign in to comment.