@@ -46,12 +46,14 @@ def __init__(self, w, h, size=2, mode=SHUFFLE):
46
46
self .drawTime = 0
47
47
48
48
# wobble vars
49
+ self .gridWidth = 2
50
+ self .gridHeight = max (2 , int (self .gridWidth / (self .w / self .h )))
51
+
49
52
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
+
55
57
self .velocities = np .array ([[0 , 0 ],
56
58
[0 , 0 ],
57
59
[0 , 0 ],
@@ -173,10 +175,20 @@ def draw(self):
173
175
glScalef (0.5 , - 0.5 , 1.0 )
174
176
175
177
glBegin (GL_QUADS )
178
+ """
176
179
glTexCoord2f(self.points[0][0], self.points[0][1]); glVertex2i(0, 0)
177
180
glTexCoord2f(self.points[1][0], self.points[1][1]); glVertex2i(self.w, 0)
178
181
glTexCoord2f(self.points[2][0], self.points[2][1]); glVertex2i(self.w, self.h)
179
182
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
+
180
192
glEnd ()
181
193
glFlush ()
182
194
glDisable (GL_TEXTURE_2D )
@@ -193,10 +205,17 @@ def initFunc():
193
205
gluOrtho2D (0.0 , w , 0.0 , h )
194
206
195
207
def keyboardFunc (key , x , y ):
208
+ global controller
196
209
if key == 'q' :
197
210
controller .quit ()
198
211
os .remove (filename )
199
212
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
+
200
219
201
220
def displayFunc ():
202
221
global controller
0 commit comments