Skip to content

Instantly share code, notes, and snippets.

Created March 30, 2014 12:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#MonthOfCode day 21 - wave
import pygame
import math
from time import sleep
SCREEN_W = 640
SCREEN_H = 480
class MovingPix():
def __init__(self , x,y ):
self.x = x
self.y = y
def adjustPosition(self, period, max_period ):
self.y =SCREEN_H/2 + 32 * math.cos(
( float(period)/max_period + ( float(self.x) /SCREEN_W) ) *
2*math.pi )
self.y = int(self.y)
def refreshScreen():
window.fill( pygame.Color('black') )
for pix in l_pix:
window.set_at( (pix.x, pix.y), pygame.Color('red'))
# init. pygame libr; create the screen and diplays a help message in the console
window = pygame.display.set_mode( (SCREEN_W,SCREEN_H) )
# init. list of all moving pixels
l_pix =list()
for i in xrange( SCREEN_W):
l_pix.append( MovingPix(i, SCREEN_H/2 ))
program_done = False
period = 0
while not program_done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
program_done = True
if event.type == pygame.MOUSEBUTTONDOWN:
l_pix[ 10 ].y = 30
# simulating energy transmission
for movingpix in l_pix:
movingpix.adjustPosition( period, 16)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment