-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvertex.py
41 lines (32 loc) · 1021 Bytes
/
vertex.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
import pygame, math
class Vertex:
def __init__(self, origin=(100, 100), color=(100, 100, 100), size=5, anchored=False):
self.color = color
self.size = size
self.connectives = []
self.anchored = anchored
self.yvel = 0
self.movements = []
self.movement = pygame.math.Vector2(0, 0)
self.rect = pygame.Rect(origin[0], origin[1], size, size)
def update(self):
for c in self.connectives:
dx, dy = self.rect.x-c.rect.x, self.rect.y-c.rect.y
angle = math.atan2(dy, dx)
mx, my = math.cos(angle), math.sin(angle)
m = (mx, my)
c.movements.append(m)
for c in self.connectives:
distance = math.dist((self.rect.x, self.rect.y), (c.rect.x, c.rect.y))
dist = distance*0.1
#if self.anchored == False:
# self.yvel += 0.2
# if self.yvel > 3:
# self.yvel = 3
# self.movements.append((0, self.yvel))
for m in self.movements:
self.movement.x += m[0]
self.movement.y += m[1]
self.movements.remove(m)
self.rect.x += self.movement.x
self.rect.y += self.movement.y