It is day two of my Pygame journey and in this python article, I am going to draw something on the Pygame display screen ranging from a simple line to a polygon! So far so good for my learning journey and I can tell you all that Pygame is indeed a very very cool Framework that you guys should really take a look at it, SDL is really something for those of us who created games with C++ a few years ago and now it is still a very popular Framework and Pygame is just the Python’s wrapper of this Framework which makes your life much easier without needs to learn the C++ programming language in order to create a fascinating game!
There is not much I can do today but just take a morning walk on the beach near my house before heading back to my production studio and start working again on my next game product.
Already, below is the entire program consisting of what I have learned so far, do enjoy reading it…
# Import and initialize the pygame library import pygame pygame.display.init() # set the caption on the panel pygame.display.set_caption("Draw Some Drawing") # Print this line on output panel if the initialize process is successful if(pygame.display.get_init() == True): print("Success initialize the game!") # Initialize a window or screen for display screen = pygame.display.set_mode([600, 600]) # Run the game until the user asks to quit running = True while running: # If the user clicks on the 'x' button on pygame display window then set running to false for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Fill the rectangles with blue color screen.fill((0,0,255)) pygame.draw.circle(screen, pygame.Color(0,0,0), (300,300), 60) # Draw black circle at the middle of screen pygame.draw.rect(screen, pygame.Color(100, 30, 165), pygame.Rect(400,30,100,100)) # Draw rectangle on screen pygame.draw.line(screen, pygame.Color(255, 25, 255), (250, 300), (300,300), width=3) # Draw line on screen pygame.draw.arc(screen, pygame.Color(255, 255, 255), pygame.Rect(400,30,100,100), 25.0, 30.0, width=3) # Draw arc on screen pygame.draw.polygon(screen, pygame.Color(200, 125, 205), [(100,100), (150, 150), (200,250), (220, 270), (500, 300), (50, 160)], width=5) # Draw polygon on screen # update the drawing and display screen pygame.display.flip() # Quit the game pygame.display.quit()
I think the best path to learn something is while you are learning it you start to do it yourself so you will understand what are you actually reading!
Hope you don’t find this type of tutorial boring at all and as a reward for your hard work of learning just like me, here is another picture for you to appreciate!