Skip to content

Commit 86bc883

Browse files
committed
enabled clock.schedule_interval() to work in panZoomExample.py PROGRESS!!!!
1 parent aa5030b commit 86bc883

File tree

3 files changed

+28
-37
lines changed

3 files changed

+28
-37
lines changed

panZoomExample.py

+9-18
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def __init__(self, width, height, *args, **kwargs):
2121
self.fps_display.label.x = 5
2222
self.fps_display.label.y = self.height - 30
2323

24+
self.main_batch = pyglet.graphics.Batch()
25+
self.wireOff_image = pyglet.image.load('wireOff.png')
26+
self.wireOff = pyglet.sprite.Sprite(self.wireOff_image, batch=self.main_batch)
27+
2428

2529
#Initialize camera values
2630
self.left = 0
@@ -30,7 +34,7 @@ def __init__(self, width, height, *args, **kwargs):
3034
self.zoom_level = 1
3135
self.zoomed_width = width
3236
self.zoomed_height = height
33-
37+
clock.schedule_interval(self.update, 1/60)
3438

3539
def init_gl(self, width, height):
3640
# Set clear color
@@ -101,30 +105,17 @@ def on_draw(self):
101105
# Set orthographic projection matrix
102106
glOrtho( self.left, self.right, self.bottom, self.top, 1, -1 )
103107

104-
# Draw quad
105-
glBegin( GL_QUADS )
106-
glColor3ub( 0xFF, 0, 0 )
107-
glVertex2i( 10, 10 )
108-
109-
glColor3ub( 0xFF, 0xFF, 0 )
110-
glVertex2i( 110, 10 )
111-
112-
glColor3ub( 0, 0xFF, 0 )
113-
glVertex2i( 110, 110 )
114-
115-
glColor3ub( 0, 0, 0xFF )
116-
glVertex2i( 10, 110 )
117-
glEnd()
118-
108+
self.main_batch.draw()
119109
self.fps_display.draw()
120110
# Remove default modelview matrix
121111
glPopMatrix()
122112

123-
def update(dt):
124-
pass
113+
def update(self, dt):
114+
print(dt)
125115

126116
def run(self):
127117
pyglet.app.run()
128118

129119

130120
App(1024, 768).run()
121+

pygletHelloWorld.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from pyglet.window import mouse
44
from pyglet.gl import *
55

6-
WIDTH = 640
7-
HEIGHT = 480
6+
width = 640
7+
height = 480
88
YELLOW = 255, 255, 0, 255
99
MIN_VECY = 200
1010
MAX_VECY = 400
@@ -18,15 +18,15 @@
1818
samples=4,
1919
depth_size=16,
2020
double_buffer=True)
21-
window = pyglet.window.Window(width=WIDTH, height=HEIGHT, config=conf)
21+
window = pyglet.window.Window(width=width, height=height, config=conf)
2222

2323
left = 0
24-
right = WIDTH
24+
right = width
2525
bottom = 0
26-
top = HEIGHT
26+
top = height
2727
zoom_level = 1
28-
zoomed_width = WIDTH
29-
zoomed_height = HEIGHT
28+
zoomed_width = width
29+
zoomed_height = height
3030
#vecx = 20
3131
#vecy = 200
3232
#mousex = 0
@@ -68,7 +68,7 @@
6868
@window.event
6969
def init_gl(width, height):
7070
# Set clear color
71-
#glClearColor(0/255, 0/255, 0/255, 0/255)
71+
glClearColor(0/255, 0/255, 0/255, 0/255)
7272

7373
# Set antialiasing
7474
glEnable( GL_LINE_SMOOTH )
@@ -83,13 +83,13 @@ def init_gl(width, height):
8383
glViewport( 0, 0, width, height )
8484

8585
@window.event
86-
def on_resize(width, height):
87-
global WIDTH, HEIGHT
86+
def on_resize(w, h):
87+
global width, height
8888
# Set window values
89-
WIDTH = width
90-
HEIGHT = height
89+
width = w
90+
height = h
9191
# Initialize OpenGL context
92-
init_gl(width, height)
92+
init_gl(w, h)
9393

9494
@window.event
9595
def on_mouse_motion(x, y, dx, dy):
@@ -124,16 +124,16 @@ def on_mouse_press(x, y, button, modifiers):
124124

125125
@window.event
126126
def on_mouse_scroll(x, y, dx, dy):
127-
global zoom_level, ZOOM_IN_FACTOR, ZOOM_OUT_FACTOR, WIDTH, HEIGHT
127+
global zoom_level, ZOOM_IN_FACTOR, ZOOM_OUT_FACTOR, width, height
128128
global left, right, bottom, top, zoomed_width, zoomed_height
129129
# Get scale factor
130130
f = ZOOM_IN_FACTOR if dy > 0 else ZOOM_OUT_FACTOR if dy < 0 else 1
131131
# If zoom_level is in the proper range
132132
if .2 < zoom_level*f < 5:
133133
zoom_level *= f
134134

135-
mouse_x = x/WIDTH
136-
mouse_y = y/HEIGHT
135+
mouse_x = x/width
136+
mouse_y = y/height
137137

138138
mouse_x_in_world = left + mouse_x*zoomed_width
139139
mouse_y_in_world = bottom + mouse_y*zoomed_height
@@ -164,9 +164,9 @@ def on_draw():
164164
# Save the default modelview matrix
165165
glPushMatrix()
166166
#global worldx, worldy
167-
window.clear()
167+
#window.clear()
168168
#glScalef(scale, scale, 0)
169-
#pyglet.gl.glClear(pyglet.gl.GL_COLOR_BUFFER_BIT)
169+
pyglet.gl.glClear(pyglet.gl.GL_COLOR_BUFFER_BIT)
170170

171171
glOrtho( left, right, bottom, top, 1, -1 )
172172

pygletHelloWorld.pyproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<SchemaVersion>2.0</SchemaVersion>
55
<ProjectGuid>17f8ad49-6306-4fc5-9d87-c019dd416f6e</ProjectGuid>
66
<ProjectHome>.</ProjectHome>
7-
<StartupFile>pygletHelloWorld.py</StartupFile>
7+
<StartupFile>panZoomExample.py</StartupFile>
88
<SearchPath>
99
</SearchPath>
1010
<WorkingDirectory>.</WorkingDirectory>

0 commit comments

Comments
 (0)