-
Notifications
You must be signed in to change notification settings - Fork 0
/
annimations.py
75 lines (67 loc) · 2.51 KB
/
annimations.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
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
import time
from winner import WINNER_LEFT, WINNER_NOBODY, WINNER_RIGHT
import drawing
class CountdownAnimation:
def __init__(self):
self.counter = 3
self.firstDrawTimeOfCurrentValue = None
self.done = False
def draw(self):
if self.firstDrawTimeOfCurrentValue is None:
self.firstDrawTimeOfCurrentValue = time.time()
else:
currentTime = time.time()
if currentTime - self.firstDrawTimeOfCurrentValue >= 1:
self.counter -= 1
self.firstDrawTimeOfCurrentValue = currentTime
if self.counter == 0:
self.done = True
return
glColor3f(1, 1, 1)
glPushMatrix()
glTranslate(310, 220, 0)
glutStrokeCharacter(GLUT_STROKE_ROMAN, ord('0') + self.counter)
glPopMatrix()
class DisplayWinners:
def __init__(self, winner):
self.animationStartTime = None
self.winner = winner
self.done = False
self.annimationLengthSeconds = 1
self.HALF_LINE_THICKNESS = 20
self.HALF_LINE_LENGTH = 80
self.HALF_EQUAL_PADDING = 40
self.RED = (1, 0, 0)
self.GREEN = (0, 1, 0)
self.BLUE = (0, 0, 1)
def _drawLeft(self):
if self.winner == WINNER_LEFT:
drawing.rectangle(160, 240, self.HALF_LINE_THICKNESS, self.HALF_LINE_LENGTH, self.GREEN)
drawing.rectangle(160, 240, self.HALF_LINE_LENGTH, self.HALF_LINE_THICKNESS, self.GREEN)
elif self.winner == WINNER_RIGHT:
drawing.rectangle(160, 240, self.HALF_LINE_LENGTH, self.HALF_LINE_THICKNESS, self.RED)
def _drawRight(self):
if self.winner == WINNER_RIGHT:
drawing.rectangle(480, 240, self.HALF_LINE_THICKNESS, self.HALF_LINE_LENGTH, self.GREEN)
drawing.rectangle(480, 240, self.HALF_LINE_LENGTH, self.HALF_LINE_THICKNESS, self.GREEN)
elif self.winner == WINNER_LEFT:
drawing.rectangle(480, 240, self.HALF_LINE_LENGTH, self.HALF_LINE_THICKNESS, self.RED)
def _drawCenter(self):
if self.winner == WINNER_NOBODY:
drawing.rectangle(320, 240 - self.HALF_EQUAL_PADDING,
self.HALF_LINE_LENGTH, self.HALF_LINE_THICKNESS, self.BLUE)
drawing.rectangle(320, 240 + self.HALF_EQUAL_PADDING,
self.HALF_LINE_LENGTH, self.HALF_LINE_THICKNESS, self.BLUE)
def draw(self):
if self.animationStartTime is None:
self.animationStartTime = time.time()
else:
if time.time() - self.animationStartTime >= self.annimationLengthSeconds:
self.done = True
return
self._drawLeft()
self._drawRight()
self._drawCenter()