Computer Science LearnITWithMrC ⛯ Year 7 Year 8 Year 9 GCSE ## What do I need to Learn?

 I need to learn how to use code and co-ordinates to create straight lines in python I need to learn how to draw shapes using just straight lines in python I need to learn how to draw squares and other shapes using co-ordinates and dimensions

## Knowledge Organiser  ## Lesson   • Save your PowerPoint as 'Pygame'

•  ### Using the code template

• In the Powerpoint you have just downloaded and saved there is a slide containing the text for our coding template.
• • Copy the text into Thonny and then run your code.

• When you run your code you should see a game window appear that is 640 by 480 like the example below. • Can you work out how to change the screen size to 1024 by 768 ?

•  • When we want to draw something in pygame we have to use the screen co-ordinates.
• Unlike programs like Scratch, Pygame and most game engines have the origin for their co-ordinates (x = 0 , y = 0) at the top left hand corner of the screen.
• • You can see here in our image above that a pixel, has been placed at the co-ordinates x = 30 , y = 40 which we would write (30,40) from the top left hand corner of the screen.
• Using that basic understanding let's see if we can draw a line.

• ### Drawing a line:

• In order to draw a line we need the co-ordinates for the start of the line and the co-ordinates for the end of the line. We are going to start in the top left corner so thats easy it will be (0,0) and we are going to draw a line to the co-ordinates we used above (30,40)
• This is the function we need to use in pygame to draw a line:

• pygame.draw.line(Where?,color?,(start x? start y?) (end x?, end y?) line thickness?)
• So lets fill it in with the co-ordinates we mentioned above (0,0)and (30,40) and we will use the colour green and a line thickness of 2

• pygame.draw.line(screen, green, (0,0), (30,40), 2)
• Look at the image below to see where to put this line of code in your template. hint: it goes between the lines that say 'your code starts here' and 'your code ends here'. • Run your code and you should get a small geen line drawn from the corner of your screen?
•  • Can you draw a longer thicker line?
• Can you draw another line that starts where your fist line ends?
• Can you draw a shape like a triangle or a square?

•  ### Drawing a rectangle:

In order to draw a rectangle we only need the co-ordinates for the top left hand corner of the rectangle and then the height and width in pixels. • pygame.draw.rect(screen, green, (30,40,50,20))
• When you run your code it should look like this:  • Can you draw a square?
• Can you use a different colour?
• Can you complete the next task it might seem familiar?

•  ### Can you draw the Microsoft logo?

• Using the rectangle command and the line command for the white cross in the middle?
•      ### Summing it all up

Lets look at the learning outcomes and decide which one best describes our current level of understanding :

Tick the one you feel is closest to your level

## Learning Outcomes I need to learn how to draw shapes using just straight lines in python

• I have a basic understanding of how I can draw shapes using just straight lines in python with a little help from my teacher
• I can show my teacher that I can draw shapes using just straight lines in python without their help.
• I can draw shapes using just straight lines in python independently and I can also explain it to others and can complete any extension tasks I am given.

## My Notes: Game Development  