Created
October 18, 2014 21:55
-
-
Save shaunhey/b1ecbf5e8c02846a3a0d to your computer and use it in GitHub Desktop.
Pygame script to generate "crawling" effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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