Drawing shapes

From TRCCompSci - AQA Computer Science
Revision as of 21:22, 21 February 2018 by Admin (talk | contribs) (Created page with "==Rectangle== You can declare some variables to use for your rectangle, they require the x coordinate, the y coordinate, the width and the height: <syntaxhighlight lang=pytho...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Rectangle

You can declare some variables to use for your rectangle, they require the x coordinate, the y coordinate, the width and the height:

LEFT = 100
TOP = 100
LENGTH = 20
WIDTH = 20
RECTCOORD = [LEFT, TOP, LENGTH, WIDTH]
rect1 = pygame.Rect(RECTCOORD)

This is the same as writing:

rect1 = pygame.Rect([100,100,20,20])

Before we can draw your rectangle to the screen we will need to define a colour to use:

RED = 255
YELLOW = 230
BLUE = 200
COLOR = (RED, YELLOW, BLUE)

Again this is the same as writing just:

COLOR = (255, 230, 200)