Skip to content

Commit 06d34a1

Browse files
author
Aaron Hill
committed
fixed step function
1 parent 14546b5 commit 06d34a1

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

screen2.py

+24-5
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ def __init__(self, w, h, size=2, mode=SHUFFLE):
4646
self.drawTime = 0
4747

4848
# wobble vars
49+
self.gridWidth = 2
50+
self.gridHeight = max(2, int(self.gridWidth / (self.w / self.h)))
51+
4952
self.maxSpeed = 0.005
50-
self.p1 = np.array([0, 0])
51-
self.points = np.array([[0, 0],
52-
[self.w, 0],
53-
[self.w, self.h],
54-
[0, self.h]], dtype=np.float32)
53+
self.points = np.array([[[x, y] for x in np.linspace(0, self.w, self.gridWidth)] for y in np.linspace(0, self.h, self.gridHeight)])
54+
self.vertCoords = np.array([[[x, y] for x in np.linspace(0, self.w, self.gridWidth)] for y in np.linspace(0, self.h, self.gridHeight)], dtype=np.float32)
55+
self.imgCoords = np.array([[[x, y] for x in np.linspace(0, self.w, self.gridWidth)] for y in np.linspace(0, self.h, self.gridHeight)], dtype=np.uint)
56+
5557
self.velocities = np.array([[0, 0],
5658
[0, 0],
5759
[0, 0],
@@ -173,10 +175,20 @@ def draw(self):
173175
glScalef(0.5, -0.5, 1.0)
174176

175177
glBegin(GL_QUADS)
178+
"""
176179
glTexCoord2f(self.points[0][0], self.points[0][1]); glVertex2i(0, 0)
177180
glTexCoord2f(self.points[1][0], self.points[1][1]); glVertex2i(self.w, 0)
178181
glTexCoord2f(self.points[2][0], self.points[2][1]); glVertex2i(self.w, self.h)
179182
glTexCoord2f(self.points[3][0], self.points[3][1]); glVertex2i(0, self.h)
183+
"""
184+
for y in range(self.gridHeight - 1):
185+
for x in range(self.gridWidth - 1):
186+
187+
glTexCoord2f(self.vertCoords[y][x][0], self.vertCoords[y][x][1]); glVertex2i(self.imgCoords[y][x][0], self.imgCoords[y][x][1])
188+
glTexCoord2f(self.vertCoords[y][x+1][0], self.vertCoords[y][x+1][1]); glVertex2i(self.imgCoords[y][x+1][0], self.imgCoords[y][x+1][1])
189+
glTexCoord2f(self.vertCoords[y+1][x+1][0], self.vertCoords[y+1][x+1][1]); glVertex2i(self.imgCoords[y+1][x+1][0], self.imgCoords[y+1][x+1][1])
190+
glTexCoord2f(self.vertCoords[y+1][x][0], self.vertCoords[y+1][x][1]); glVertex2i(self.imgCoords[y+1][x][0], self.imgCoords[y+1][x][1])
191+
180192
glEnd()
181193
glFlush()
182194
glDisable(GL_TEXTURE_2D)
@@ -193,10 +205,17 @@ def initFunc():
193205
gluOrtho2D(0.0, w, 0.0, h)
194206

195207
def keyboardFunc(key, x, y):
208+
global controller
196209
if key == 'q':
197210
controller.quit()
198211
os.remove(filename)
199212
exit()
213+
elif key == 'r':
214+
for i in range(controller.gridWidth):
215+
for j in range(controller.gridHeight):
216+
controller.vertCoords[i][j][0] += random.random() * 10 - 5
217+
controller.vertCoords[i][j][1] += random.random() * 10 - 5
218+
200219

201220
def displayFunc():
202221
global controller

0 commit comments

Comments
 (0)