Skip to content

Instantly share code, notes, and snippets.

@shaunhey
Created December 5, 2015 21:45
Show Gist options
  • Save shaunhey/61d331d82395f93bcd3b to your computer and use it in GitHub Desktop.
Save shaunhey/61d331d82395f93bcd3b to your computer and use it in GitHub Desktop.
Pygame script to create a waving flag effect
import pygame
def main():
arc = 0.25
base_angle = 0.0
circle_width = 20
circle_height = 20
fps = 60
speed = 0.1
window_width = 800
window_height = 600
x_scale = 0.4
y_scale = 0.3
pygame.init()
screen = pygame.display.set_mode((window_width, window_height))
background = pygame.Surface(screen.get_size())
background = background.convert()
clock = pygame.time.Clock()
while 1:
clock.tick(fps);
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
base_angle += speed
background.fill((0,0,0))
for y in range(1, (window_height / circle_height)-1):
for x in range(1, (window_width / circle_width)-1):
angle = base_angle + (x*x_scale) + (y*y_scale)
pygame.draw.arc(background, (200,200,200),(x*circle_width, y*circle_height, circle_width, circle_height), angle, angle+arc)
screen.blit(background, (0,0))
pygame.display.flip()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment