2 |
|
|
3 |
from java.lang import Math |
from java.lang import Math |
4 |
|
|
5 |
|
from types import ClassType |
6 |
|
|
7 |
# A jython test program for papers |
# A jython test program for papers |
8 |
# Load using gldemo.py |
# Load using gldemo.py |
9 |
|
|
34 |
if k == "F12": |
if k == "F12": |
35 |
currentScene = DummyScene() |
currentScene = DummyScene() |
36 |
AbstractUpdateManager.setNoAnimation() |
AbstractUpdateManager.setNoAnimation() |
37 |
if k == "F1": |
if k in scenebindings.keys(): |
38 |
currentScene = PaperScene() |
setCurrentScene(k) |
|
AbstractUpdateManager.setNoAnimation() |
|
|
if k == "F2": |
|
|
currentScene = MultiPaperScene() |
|
|
AbstractUpdateManager.setNoAnimation() |
|
39 |
if k == "t": |
if k == "t": |
40 |
retexture(); |
retexture(); |
41 |
if k == "b": |
if k == "b": |
212 |
for i in range(0,self.w*self.h): |
for i in range(0,self.w*self.h): |
213 |
self.pq[i] = getpaper(self.seed + i) |
self.pq[i] = getpaper(self.seed + i) |
214 |
|
|
215 |
|
def mouse(self, ev): |
216 |
|
if ev.getID() == ev.MOUSE_CLICKED: |
217 |
|
x,y = ev.getX(), ev.getY() |
218 |
|
|
219 |
|
print x,y |
220 |
|
index = 0 |
221 |
|
for box in self.boxes: |
222 |
|
if (box[0] <= x <= box[2] and |
223 |
|
box[1] <= y <= box[3]): |
224 |
|
setCurrentScene("F1") |
225 |
|
global currentScene |
226 |
|
currentScene.seed = self.seed + index |
227 |
|
currentScene.initpaper() |
228 |
|
index += 1 |
229 |
|
|
230 |
|
|
231 |
def key(self, k): |
def key(self, k): |
232 |
|
if k >= "0" and k <= "9": self.seed = self.seed * 10 + int(k) |
233 |
|
if k == "BackSpace" or k == "Backspace": self.seed = self.seed / 10 |
234 |
if k == "v": |
if k == "v": |
235 |
self.seed = rng.nextInt(200000000) |
self.seed = rng.nextInt(200000000) |
236 |
|
if k == "v" or k == "Return": |
237 |
self.initpaper() |
self.initpaper() |
238 |
AbstractUpdateManager.setNoAnimation() |
AbstractUpdateManager.setNoAnimation() |
239 |
AbstractUpdateManager.chg() |
AbstractUpdateManager.chg() |
249 |
cs2 = vs.coords.affineCoordsys(0, 1, 0, 0, scale/cs1w, 0, 0, scale/cs1h) |
cs2 = vs.coords.affineCoordsys(0, 1, 0, 0, scale/cs1w, 0, 0, scale/cs1h) |
250 |
vs.matcher.add(cs2, "tex") |
vs.matcher.add(cs2, "tex") |
251 |
|
|
252 |
|
self.boxes = [] |
253 |
cs1 = range(0,self.w*self.h) |
cs1 = range(0,self.w*self.h) |
254 |
for i in range(0,self.w*self.h): |
for i in range(0,self.w*self.h): |
255 |
if i >= len(self.pq): break |
if i >= len(self.pq): break |
256 |
cs1[i] = vs.coords.affineCoordsys(0, 100-i, |
|
257 |
(i%self.w+.5)*1200.0/self.w, |
x = (i%self.w+.5)*1200.0/self.w |
258 |
(i/self.w+.5)*900.0/self.h, |
y = (i/self.w+.5)*900.0/self.h |
259 |
cs1w, 0, 0, cs1h) |
|
260 |
|
self.boxes.append( (x - cs1w, y - cs1h, |
261 |
|
x + cs1w, y + cs1h ) ) |
262 |
|
|
263 |
|
cs1[i] = vs.coords.affineCoordsys(0, 100-i, x, y, cs1w, 0, 0, cs1h) |
264 |
|
|
265 |
|
|
266 |
vs.matcher.add(cs1[i], str(i)) |
vs.matcher.add(cs1[i], str(i)) |
267 |
|
|
268 |
vs.map.put(self.pq[i], cs1[i], cs2) |
vs.map.put(self.pq[i], cs1[i], cs2) |
345 |
|
|
346 |
|
|
347 |
|
|
348 |
currentScene = DummyScene() |
scenebindings = { |
349 |
|
"F1": PaperScene, |
350 |
|
"F2": MultiPaperScene, |
351 |
|
"F12": DummyScene, |
352 |
|
} |
353 |
|
|
354 |
|
def setCurrentScene(k): |
355 |
|
global scenes, currentScene |
356 |
|
|
357 |
|
if not "scenes" in globals().keys(): scenes = {} |
358 |
|
|
359 |
|
# Instantiate if necessary |
360 |
|
if ((not scenes.has_key(k)) or |
361 |
|
scenes[k] == currentScene): |
362 |
|
print "Instantiating new", k, "scene" |
363 |
|
scenes[k] = scenebindings[k]() |
364 |
|
else: |
365 |
|
print "Changing to", k, "scene" |
366 |
|
|
367 |
|
# Set current scene |
368 |
|
currentScene = scenes[k] |
369 |
|
AbstractUpdateManager.setNoAnimation() |
370 |
|
AbstractUpdateManager.chg() |
371 |
|
|
372 |
|
|
373 |
|
setCurrentScene("F12") |
374 |
|
|
375 |
|
|
376 |
|
|
377 |
|
|