-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsprites.py
More file actions
executable file
·139 lines (117 loc) · 4.6 KB
/
Copy pathsprites.py
File metadata and controls
executable file
·139 lines (117 loc) · 4.6 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# importing the codes settings
from settings import *
# define a sprite to keep track of where the mouse is
class MouseSprite(pygame.sprite.Sprite):
def __init__(self, spot):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((3, 3))
self.image.fill(GREEN)
self.image.set_colorkey(GREEN)
self.rect = self.image.get_rect()
self.rect.center = spot
self.center = self.rect.center
def move(self, spot):
self.rect.center = spot
# defining a sprite that tells user how to draw shapes
class HelpText(pygame.sprite.Sprite):
def __init__(self):
# initialising the sprite
pygame.sprite.Sprite.__init__(self)
self.image = basicFont.render('p: point c: circle l: line x: clear', True, BLACK, WHITE)
self.rect = self.image.get_rect()
self.rect.topleft = (5, 5)
def clear(self):
# this clears the area
self.image = basicFont.render(' ', True, BLACK, WHITE)
self.rect = self.image.get_rect()
self.rect.topleft = (5, 25)
def circle(self, thingProcess):
# this draws instructions on how to make circles
if not thingProcess:
self.image = basicFont.render('click to make the center of a circle', True, BLACK, WHITE)
else:
self.image = basicFont.render('click to make the outside of the circle', True, BLACK, WHITE)
self.rect = self.image.get_rect()
self.rect.topleft = (5, 25)
def point(self):
# this draws instructions for making a point
self.image = basicFont.render('click to make a point', True, BLACK, WHITE)
self.rect = self.image.get_rect()
self.rect.topleft = (5, 25)
def line(self, thingProcess):
# this draws instructions for making a line
if not thingProcess:
self.image = basicFont.render('click to make one end of the line', True, BLACK, WHITE)
else:
self.image = basicFont.render('click to make the other end of the line', True, BLACK, WHITE)
self.rect = self.image.get_rect()
self.rect.topleft = (5, 25)
# defining a line sprite
class Line(pygame.sprite.Sprite):
def __init__(self, p1):
# initialising the sprite
global allSprites
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((WIDTH, HEIGHT))
self.image.fill(GREEN)
self.image.set_colorkey(GREEN)
self.rect = self.image.get_rect()
self.rect.topleft = (0, 0)
self.p = p1
p = Point(p1)
allSprites.add(p)
def change(self, p2):
# updating what the line looks like
self.image.fill(GREEN)
pygame.draw.line(self.image, BLACK, self.p, p2, 2)
# defining a point sprite
class Point(pygame.sprite.Sprite):
def __init__(self, p1):
# initialising the sprite
pygame.sprite.Sprite.__init__(self)
global points
self.image = pygame.Surface((14, 14))
self.image.fill(GREEN)
self.image.set_colorkey(GREEN)
self.radius = 2
pygame.draw.circle(self.image, BLUE, (7, 7), self.radius)
self.rect = self.image.get_rect()
self.rect.center = (p1[0], p1[1])
self.center = self.rect.center
points.add(self)
def grow(self):
# this grows the point when the mouse is on it
self.image.fill(GREEN)
self.radius = 5
pygame.draw.circle(self.image, RED, (7, 7), self.radius)
def update(self):
# this shrinks the sprite when the mouse is not on it
self.image.fill(GREEN)
self.radius = 2
pygame.draw.circle(self.image, BLUE, (7, 7), self.radius)
# defining a circle sprite
class CircleSprite(pygame.sprite.Sprite):
def __init__(self, p1, p2):
# initialising the sprite
global allSprites
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((WIDTH, HEIGHT))
self.image.fill(GREEN)
self.image.set_colorkey(GREEN)
radius = math.sqrt((p2[0] - p1[0]) ** 2 + (p2[1] - p1[1]) ** 2)
if radius < 3:
radius = 4
pygame.draw.circle(self.image, BLACK, p1, int(radius), 2)
self.center = p1
self.rect = self.image.get_rect()
self.rect.topleft = (0, 0)
p = Point(p1)
allSprites.add(p)
def change(self, p2):
# this updates what the circle looks like
self.image.fill(GREEN)
p1 = self.center
radius = math.sqrt((p2[0] - p1[0]) ** 2 + (p2[1] - p1[1]) ** 2)
if radius < 3:
radius = 4
pygame.draw.circle(self.image, BLACK, self.center, int(radius), 2)