-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch_pyglet.py
50 lines (40 loc) · 1.07 KB
/
switch_pyglet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pyglet
from pyglet.window import key
from pyglet.gl import gl
# colors
on_colour = (0, .5, .8, 1)
off_colour = (0.5,0,0.8,1)
window = pyglet.window.Window(width=300, height=300, caption='Press key/button to start')
window.set_fullscreen(True)
# sets the background color
gl.glClearColor(*off_colour)
window.clear()
boat = pyglet.media.load("audio_tracks\\Boat_Amie.wav", streaming=False)
player = pyglet.media.Player()
player.queue(boat)
player.EOS_LOOP = 'loop'
firston = False
@window.event
def on_key_press(symbol, modifiers):
global firston
if symbol == key.R:
print('Repeat play')
boat.play()
else:
if not firston:
firston = True
player.play()
if firston:
print("On colour")
gl.glClearColor(*on_colour)
window.clear()
@window.event
def on_key_release(symbol, modifiers):
global firston
player.pause()
firston = False
if not firston:
print("Off colour")
gl.glClearColor(*off_colour)
window.clear()
pyglet.app.run()