-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtechDemo.py
89 lines (74 loc) · 2.45 KB
/
techDemo.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from cmu_112_graphics import *
import camTracker
import audioDriver
import threading
class Game(App):
def appStarted(app):
app.debugMode = True
app.maxThreads = 4
app.runThreads = True
app.timerDelay = 5
app.camThreshold = .9
app.cam = camTracker.camTracker()
app.xPos = 0
app.yPos = 0
app.audioDriver = audioDriver.audioDriver()
thread = camThread(2, "camThread", app)
thread.start()
def keyPressed(app, event):
#controlling camera sensitivity
if event.key == 'Up':
if(app.camThreshold) < .95:
app.camThreshold += .05
elif event.key == 'Down':
if(app.camThreshold) > .5:
app.camThreshold -= .05
elif event.key == 'Space':
app.cam.toggleFilter()
elif event.key == 's':
app.playSound("HitShortLeft4.wav")
elif event.key == 'd':
app.playSound("HitShortLeft2.wav")
def playSound(app, name):
thread = audioDriver.audioThread(1, "soundThread", name)
thread.start()
def timerFired(app):
pass
#print(app.countCamThreads())
#print(threading.enumerate()[0])
'''
def countCamThreads(app):
threads = threading.enumerate()
count = 0
for t in threads:
if t.name == "camThread":
count += 1
return count
'''
def camTick(app,):
output = app.cam.getCoords(app.camThreshold,app.debugMode)
if(output != None):
(xScale, yScale) = output
app.xPos = app.width*(1-xScale) #camera's flipped
app.yPos = app.height*yScale
def redrawAll(app, canvas):
if(app.debugMode):
app.drawReferenceMarker(canvas)
def drawReferenceMarker(app, canvas):
r = 10
canvas.create_oval(app.xPos-r, app.yPos-r, app.xPos+r, app.yPos+r,
fill = "red", outline = "")
def closeApp(app):
app.audioDriver.close()
#Threading Tutorial: from here
#https://www.tutorialspoint.com/python/python_multithreading.htm
class camThread(threading.Thread):
def __init__(self, threadID, name, game):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.game = game
def run(self):
while self.game._running:
self.game.camTick()
Game(width=900,height=600)