-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBayesFace.py
62 lines (47 loc) · 1.1 KB
/
BayesFace.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
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
from face import Face
from calculation import *
class BayesFace(Face):
def __init__(self):
self.stream = tweetFilter('')
self.tweet = None
def idleFunc(self):
try:
newTweet = self.stream.next()
self.tweet = getBayesSentiment(newTweet)
if self.tweet != None:
glutPostRedisplay()
except Exception as e:
print(e)
return
def drawScene(self):
glMatrixMode(GL_MODELVIEW)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
print(self.tweet)
if self.tweet == None:
eye = 0
mouth = 0
else:
eye = self.tweet[0]['arousal']*10
mouth = (self.tweet[0]['valence']-5)/10
if mouth <= 0:
eye = -eye
glPushMatrix()
self.drawEyebrow(eye)
self.drawEye(eye)
self.drawNose()
self.drawMouth(mouth, 0)
glRotatef(180, 0, 1, 0)
self.drawEyebrow(eye)
self.drawEye(eye)
self.drawNose()
self.drawMouth(mouth, 0)
glPopMatrix()
if self.tweet != None:
self.printText(self.tweet[1])
glFlush()
glutSwapBuffers()
if __name__ == "__main__":
BayesFace().main()