Skip to content

Instantly share code, notes, and snippets.

@shaunhey
Created October 18, 2014 21:55
Show Gist options
  • Save shaunhey/b1ecbf5e8c02846a3a0d to your computer and use it in GitHub Desktop.
Save shaunhey/b1ecbf5e8c02846a3a0d to your computer and use it in GitHub Desktop.
Pygame script to generate "crawling" effect
import pygame, random, sys, time
def main():
width = 640
height = 480
x = width / 2
y = height / 2
shade = 0
pygame.init()
screen = pygame.display.set_mode((width, height))
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
direction = random.randint(1, 4)
if direction == 1: x = (x - 1) % width
elif direction == 2: x = (x + 1) % width
elif direction == 3: y = (y - 1) % height
elif direction == 4: y = (y + 1) % height
shade = (shade + 1) % 255
screen.set_at((x, y), (shade, shade, shade))
if shade == 0: # throttle the screen updates
pygame.display.flip()
time.sleep(0.001)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment