![]() |
2011-06-20
, 12:48
|
|
Posts: 1,012 |
Thanked: 817 times |
Joined on Jul 2007
@ France
|
#2
|
The Following 2 Users Say Thank You to Khertan For This Useful Post: | ||
I am teaching myself python and pygame.
I took a simple example and modified it in order to understand how it works. My source code is here:
import pygame
import pygame.gfxdraw # not sure why needed
import random
pygame.init() # initialize the pygame module
screen = pygame.display.set_mode((800,450)) # set the window size
pygame.display.set_caption('Circles') # set the window title
pygame.mouse.set_visible(0) # hide the mouse pointer
screen.fill((0, 0, 0)) # fill the ascreen in black
while 1:
for event in pygame.event.get(): # read all the events
if event.type == pygame.QUIT: sys.exit() # was the x pressed
r=random.randint(0,255)
g=random.randint(0,255)
b=random.randint(0,255)
x=random.randint(0,800)
y=random.randint(0,450)
d=random.randint(0,800)
s = pygame.Surface(screen.get_size(), pygame.SRCALPHA, 32) # set the surface
pygame.gfxdraw.filled_circle(s, x, y, d, (r, g, b)) # draw a circle on the surface
screen.fill((0, 0, 0)) # clear the screen so all other objects removed
screen.blit(s, (0, 0)) # blit draws the screen
pygame.display.flip() # display the screen
My questions are:
1) If I import pygame, why do I need to seperately import pygame.gfxdraw?
2) Why do I need to set the surface and what does this do exactly?
3) Why do I need a screen.blit?
Hope someone can help so I can progress my learning!