Monday, 7 December 2015

Pygame: Draw sequence of lines

'pygame.draw.lines()' is used to draw sequence of lines on a Surface.

Syntax
lines(Surface, color, closed, pointlist, width=1)

If the closed argument is true an additional line segment is drawn between the first and last points.
#import pygame
import pygame

#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)

clock = pygame.time.Clock()

while(dead==False):
 for event in pygame.event.get(): 
  if event.type == pygame.QUIT:
   dead = True
  
  screen.fill(WHITE)
  lines=[[50,50], [450, 450], [450,50], [50, 450] ]
  pygame.draw.lines(screen, RED, True, lines, 3)
  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