-
Notifications
You must be signed in to change notification settings - Fork 0
/
IHM.py
72 lines (60 loc) · 2.28 KB
/
IHM.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
import pygame
import os
import math
# Class for a visual talking indicator using Pygame.
class TalkingIndicator:
def __init__(self, system):
self.init_pygame()
self.system = system
# Variables for the beating sphere
self.max_radius = 50
self.min_radius = 30
self.radius = self.min_radius
self.speed = 3
@property
def talking(self):
return self.system.talking
@property
def speaking(self):
return self.system.speaking
@property
def thinking(self):
return self.system.thinking
def init_pygame(self):
pygame.init()
self.screen = pygame.display.set_mode((400, 400))
pygame.display.set_caption("Voice Indicator")
self.clock = pygame.time.Clock()
def run(self):
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
os._exit(0)
self.screen.fill((0,0,0))
# If speaking, make the sphere beat faster, bigger and change color
if self.speaking:
self.max_radius = 100
self.min_radius = 90
self.speed = 10
self.color = (255, 140, 0) # nice orange
self.width = 5
else:
self.min_radius = 80
self.max_radius = 60
self.speed = 5
self.color = (0, 255, 255) # cyan
self.width = 15
# Calculate the new radius using a sine wave for smooth transitions
radius = self.min_radius + (self.max_radius - self.min_radius) * (math.sin(pygame.time.get_ticks() * self.speed / 1000) + 1) / 2
# Clear the screen
self.screen.fill((0, 0, 0))
# Draw the beating sphere
pygame.draw.circle(self.screen, self.color, (200,200), int(radius),self.width)
if self.thinking:
pygame.draw.circle(self.screen, (255,0,124), (200,200), 40)
# Draw a circle at the bottom, color depends on self.talking
color = (0,255,0) if self.talking else (255,0,0)
pygame.draw.circle(self.screen, color, (200, 350), 25)
pygame.display.flip()
self.clock.tick(60)