'''
Created on Sep 5, 2011
@author:
'''
'''
Creates an animation of snowflakes falling against a night sky.
'''
import pygame
import random
import sys
from snowflake import Snowflake
from windy import Windy
BACKGROUND_COLOR = (0, 0, 0)
SNOWFLAKE_COLOR = (255, 255, 255)
WINDOW_DIMENSIONS = [400, 400]
window = pygame.display.set_mode(WINDOW_DIMENSIONS)
pygame.display.set_caption("Snow Animation")
clock = pygame.time.Clock()
done = False
def initialize_snowflake():
''' creates a series of snowflakes'''
snowflake = [[random.randrange(0,400), random.randrange(0,400)]for _ in range(60)]
windy = [[random.randrange(0,400), random.randrange(0,400)]for _ in range(60)]
return snowflake
return windy
def initialize_gui():
''' creates a window and sets the title'''
window = pygame.display.set_mode(WINDOW_DIMENSIONS)
pygame.display.set_caption("Snow Animation")
return window
def display_snowflake(snowflake,window):
'''displays the snowflakes in the window'''
window.fill(BACKGROUND_COLOR)
for _ in range(len(snowflake)):
Snowflake.draw(window, Snowflake.color, Snowflake.position, Snowflake.radius)
snowflake[_][1] += 1
if snowflake[_][1] > 400:
y = random.randrange(-50,-10)
snowflake[_][1] = y
x = random.randrange(0,400)
snowflake[_][0] = x
def run(snowflakes, window):
'''executes the animation loop to create a window and let the snow being'''
while not pygame.event.peek(pygame.QUIT):
Snowflake.draw(window, Snowflake.color, Snowflake.position, Snowflake.radius)
pygame.display.flip()
pygame.event.clear()
clock.tick(60)
def main(sysargs=None):
pygame.init()
snowflake = initialize_snowflake()
window = initialize_gui()
run(snowflake, window)
pygame.quit()
if __name__=='__main__':
sys.exit(main())
snowflake
'''
Created on Sep 5, 2011
@author:
'''
import pygame
import random
class Snowflake(object):
'''
Represents 1 snowflake in the snow animation
'''
color = (255, 255, 255)
radius = 2
def __init__(self,_color,initial_position):
'''
creates a snowflake with the specified color, at a random position
'''
self.__color = _color
self.__position = initial_position
@property
def position(self):
'''returns the location of the snowflake'''
return self.__position
@property
def color(self):
return self.__color
@position.setter
def position(self, position):
'''sets the position of the snowflake '''
x = (random.randrange(0,400))
y = (random.randrange(0,400))
self.__positon = (x,y)
@color.setter
def color(self, value):
self.__color = value
def draw(self,window,color,radius):
pygame.draw.circle(window,color,self.position,radius)
def move(self, pixels):
self.pixels =+ 1
if Snowflake[_][1] > 400:
y = random.randrange(-50,-10)
Snowflake[_][1] = y
x = random.randrange(0,400)
Snowflake[_][0] = x
Attached File(s)
-
snow9-7.zip (6.49K)
Number of downloads: 43

New Topic/Question
Reply




MultiQuote





|