Tuesday 8 December 2015

Pygame: draw a circle

‘pygame.draw.circle()’ is used to draw a circle.

Syntax
circle(Surface, color, pos, radius, width=0)


‘pos’ is the center of the circle. If width is zero then the circle will be filled.
#import pygame
import pygame
import math

#initialize game engine
pygame.init()

#Open a window
size = (500, 500)
screen = pygame.display.set_mode(size)

#Set title to the window
pygame.display.set_caption("Hello World")

dead=False

#Initialize values for color (RGB format)
WHITE=(255,255,255)
RED=(255,0,0)
GREEN=(0, 255, 0)
BLUE=(0,0,255)
BLACK=(0,0,0)

clock = pygame.time.Clock()
PI=math.pi

while(dead==False):
 for event in pygame.event.get(): 
  if event.type == pygame.QUIT:
   dead = True
  
  screen.fill(WHITE)
  pygame.draw.circle(screen, BLACK, [250, 250], 200, 0)
  pygame.draw.circle(screen, BLUE, [250, 250], 150, 0)
  pygame.draw.circle(screen, GREEN, [250, 250], 100, 0)
  pygame.draw.circle(screen, RED, [250, 250], 50, 0)
  
  pygame.display.flip()
  clock.tick(60)
   
#Shutdown display module
pygame.display.quit()

Run above program, you will get following output.





Previous                                                 Next                                                 Home

No comments:

Post a Comment