PyGame is a graphics library made for Python that we are going to use to create programs with graphics.
Here is the documentation for all of the PyGame libraries: https://www.pygame.org/docs/. This page also includes links to tutorials and example code on how to use PyGame. There is a lot to learn that we will not get to in this course.
This section will give an introduction to drawing basic shapes using the PyGame graphical library.
1. Download the Graphics Template.py file and use it as a starting point for each pygame program you make from now on.
Read through the Part 5: Graphics in PyGame tutorial.
2. Make sure that you read the corresponding portions of Chapter 5 - Programming Arcade Games as suggested in the Part 5 - Graphics tutorial.
3. Attempt to explain what each section of code does in the example program. Experiment with the graphics commands in #7.
4. Complete and hand in Chapter 5 Graphics Worksheet.
5. Create and hand in your own graphics assignment 'Still Life' as per the Part 5 - Graphics tutorial.
Submit:
import pygame'
should only appear once, and at the top of your program. This is also true with any other library, such as when you import the random library.Q: How on earth do I use a loop to draw multiple graphic objects?
A: Use a loop to increment an integer value. You can put one or more draw statements in the loop. Use your incrementing variable to either be, or modify a parameter for one of the shapes you wish to draw.
For example:
for x in range(0, 100, 5):
pygame.draw.rect(screen, RED, [55 + x, 50, 5, 25], 0)