Created
July 7, 2014 09:17
-
-
Save chris-martin/50c494675044607c0bd3 to your computer and use it in GitHub Desktop.
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 math | |
import pygame | |
from pygame import draw | |
import sys | |
import time | |
pygame.init() | |
size = width, height = 500, 200 | |
screen = pygame.display.set_mode(size) | |
scale = 35 | |
offset = 0 | |
while True: | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
sys.exit() | |
screen.fill(0xffffff) | |
for i in xrange(0, width / scale + 1): | |
x = (i * scale) - ((offset * scale) % scale) | |
draw.line(screen, 0xa0a0a0, (x, 0), (x, height)) | |
for i in xrange(0, height / scale / 2 + 1): | |
y = i * scale | |
draw.line(screen, 0xa0a0a0, (0, height/2 + y), (width, height/2 + y)) | |
draw.line(screen, 0xa0a0a0, (0, height/2 - y), (width, height/2 - y)) | |
for x in xrange(0, width): | |
y = math.sin(float(x) / scale + offset) * scale + (height * 0.5) | |
draw.circle(screen, 0x00ff00, (x, int(y)), 1) | |
pygame.display.flip() | |
offset += 0.05 | |
time.sleep(.008) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment