Exemple #1
0
 def update(self):
     # The performance trick is that we don't keep a history, 
     # e.g. no list with all the previous segments in the growing root.
     # We simply keep the position and heading of the last segment.
     # The previous segments have been rendered in a texture, i.e. they are "frozen".
     self.x, self.y = coordinates(self.x, self.y, self.radius, self.angle)
     self.angle += random(-self.step, self.step)
     self.time *= 0.8 + random(0.2)
 def update(self):
     # Calculate new position from the current heading and segment size.
     # The coordinates() function takes a point, a distance and an angle,
     # and returns the point at the given angle and distance from the given point.
     x, y = coordinates(self.x, self.y, self.radius*3, self.angle)
     self.angle += choice((-self.step, self.step))
     # Confine the snake to the visible area.
     self.x = max(0, min(x, 500))
     self.y = max(0, min(y, 500))
     # Add the new segment. 
     # Snake can have 200 segments maximum.
     self.trail.insert(0, (x, y, self.radius))
     self.trail = self.trail[:200]