Skip to content

Instantly share code, notes, and snippets.

@ralphbean
Created June 25, 2012 15:37
Show Gist options
  • Select an option

  • Save ralphbean/2989313 to your computer and use it in GitHub Desktop.

Select an option

Save ralphbean/2989313 to your computer and use it in GitHub Desktop.
_last_called = time.time()
def animate():
global r
global _last_called
now = time.time()
if now - _last_called > 2: # 2 is in seconds
# Remember when I was called last
_last_called = now
# Determine a new random position
x = random.randint(0, width)
y = random.randint(0, height)
# pygame.Rect needs 'left', 'top', 'width', 'height'
# The 100, and the 50 are borrowed from the Surface above
r = pygame.Rect(x, y, 100, 50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment