3
3
from pyglet .window import mouse
4
4
from pyglet .gl import *
5
5
6
- WIDTH = 640
7
- HEIGHT = 480
6
+ width = 640
7
+ height = 480
8
8
YELLOW = 255 , 255 , 0 , 255
9
9
MIN_VECY = 200
10
10
MAX_VECY = 400
18
18
samples = 4 ,
19
19
depth_size = 16 ,
20
20
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 )
22
22
23
23
left = 0
24
- right = WIDTH
24
+ right = width
25
25
bottom = 0
26
- top = HEIGHT
26
+ top = height
27
27
zoom_level = 1
28
- zoomed_width = WIDTH
29
- zoomed_height = HEIGHT
28
+ zoomed_width = width
29
+ zoomed_height = height
30
30
#vecx = 20
31
31
#vecy = 200
32
32
#mousex = 0
68
68
@window .event
69
69
def init_gl (width , height ):
70
70
# Set clear color
71
- # glClearColor(0/255, 0/255, 0/255, 0/255)
71
+ glClearColor (0 / 255 , 0 / 255 , 0 / 255 , 0 / 255 )
72
72
73
73
# Set antialiasing
74
74
glEnable ( GL_LINE_SMOOTH )
@@ -83,13 +83,13 @@ def init_gl(width, height):
83
83
glViewport ( 0 , 0 , width , height )
84
84
85
85
@window .event
86
- def on_resize (width , height ):
87
- global WIDTH , HEIGHT
86
+ def on_resize (w , h ):
87
+ global width , height
88
88
# Set window values
89
- WIDTH = width
90
- HEIGHT = height
89
+ width = w
90
+ height = h
91
91
# Initialize OpenGL context
92
- init_gl (width , height )
92
+ init_gl (w , h )
93
93
94
94
@window .event
95
95
def on_mouse_motion (x , y , dx , dy ):
@@ -124,16 +124,16 @@ def on_mouse_press(x, y, button, modifiers):
124
124
125
125
@window .event
126
126
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
128
128
global left , right , bottom , top , zoomed_width , zoomed_height
129
129
# Get scale factor
130
130
f = ZOOM_IN_FACTOR if dy > 0 else ZOOM_OUT_FACTOR if dy < 0 else 1
131
131
# If zoom_level is in the proper range
132
132
if .2 < zoom_level * f < 5 :
133
133
zoom_level *= f
134
134
135
- mouse_x = x / WIDTH
136
- mouse_y = y / HEIGHT
135
+ mouse_x = x / width
136
+ mouse_y = y / height
137
137
138
138
mouse_x_in_world = left + mouse_x * zoomed_width
139
139
mouse_y_in_world = bottom + mouse_y * zoomed_height
@@ -164,9 +164,9 @@ def on_draw():
164
164
# Save the default modelview matrix
165
165
glPushMatrix ()
166
166
#global worldx, worldy
167
- window .clear ()
167
+ # window.clear()
168
168
#glScalef(scale, scale, 0)
169
- # pyglet.gl.glClear(pyglet.gl.GL_COLOR_BUFFER_BIT)
169
+ pyglet .gl .glClear (pyglet .gl .GL_COLOR_BUFFER_BIT )
170
170
171
171
glOrtho ( left , right , bottom , top , 1 , - 1 )
172
172
0 commit comments