Added joint path drawing
This commit is contained in:
parent
b9b4db9c0f
commit
b956e515b8
1 changed files with 15 additions and 2 deletions
17
pendel.py
17
pendel.py
|
@ -45,6 +45,13 @@ class PendelSim(Game):
|
|||
self.init_data()
|
||||
self.mousedown = False
|
||||
self.mousepos = (0,0)
|
||||
self.pathsurface = pygame.Surface( (self._width, self._height) )
|
||||
self.resetpath()
|
||||
|
||||
def resetpath(self):
|
||||
BLACK = (0,0,0)
|
||||
self.pathsurface.fill( BLACK )
|
||||
|
||||
|
||||
def init_data(self):
|
||||
self.staff_lengths = staff_lengths = [ randint(150,200), randint(100,200), randint(100,150) ]
|
||||
|
@ -54,6 +61,7 @@ class PendelSim(Game):
|
|||
joint_c = joint_b - Vector(-staff_lengths[2],0)
|
||||
self.joints = [fixed_joint, joint_a, joint_b, joint_c ]
|
||||
self.joint_speed = [ Vector(0,0), Vector(0,0), Vector(0,0), Vector(0,0) ]
|
||||
self.old_joints = self.joints
|
||||
|
||||
def on_update(self, dtime):
|
||||
new_joints = self.joints[:]
|
||||
|
@ -71,6 +79,7 @@ class PendelSim(Game):
|
|||
for i in range(0,4):
|
||||
self.joint_speed[i] = (new_joints[i] - self.joints[i]) / dtime
|
||||
|
||||
self.old_joints = self.joints
|
||||
self.joints = new_joints
|
||||
|
||||
def on_render(self, surface):
|
||||
|
@ -80,9 +89,12 @@ class PendelSim(Game):
|
|||
WHITE = (255,255,255)
|
||||
BLUE = (0,0,255)
|
||||
|
||||
staff_colors = [ RED, GREEN, BLUE ]
|
||||
staff_colors = [ GREEN, RED, BLUE ]
|
||||
|
||||
surface.fill(BLACK)
|
||||
for i in range(2,4):
|
||||
pygame.draw.line(self.pathsurface, staff_colors[(i-1)%3], self.old_joints[i].astuple(), self.joints[i].astuple(), 2)
|
||||
|
||||
surface.blit(self.pathsurface, (0,0))
|
||||
|
||||
|
||||
for i in range(4-1):
|
||||
|
@ -100,6 +112,7 @@ class PendelSim(Game):
|
|||
elif event.type == MOUSEBUTTONUP:
|
||||
self.mousedown = False
|
||||
self.mousepos = event.pos[:]
|
||||
self.resetpath()
|
||||
elif event.type == MOUSEMOTION:
|
||||
self.mousepos = event.pos[:]
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue