-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot.py
45 lines (31 loc) · 1.27 KB
/
dot.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
import pygame
class Dot:
def __init__(self,position:tuple, color:tuple, radius:int) -> None:
super().__init__()
self.position_x, self.position_y = position
self.position = position
self.radius = radius
self.color = color
self.defaut_color = color
self.seleced_color = (0,255,0)
self.over_color = (255,0,0)
self.over = False
self.on_focus = False
def toggle_over_state(self) -> None:
self.over = not self.over
def set_over_color(self) -> None:
self.color = self.over_color
def set_seleced_color(self) -> None:
self.color = self.seleced_color
def set_defaut_color(self) -> None:
self.color = self.defaut_color
def set_position(self, position) -> None:
self.position = position
self.position_x,self.position_y = self.position
def is_on_focus(self, position) -> bool:
deltaX = (self.position_x - position[0]) ** 2
deltaY = (self.position_y - position[1]) ** 2
self.on_focus = self.radius > (deltaX + deltaY) ** 0.5
def update(self, surface, mouse_position,show_dots):
if show_dots:pygame.draw.circle(surface, self.color,(self.position), self.radius)
self.is_on_focus(mouse_position)