Turtle Python Drawing Flags with Python J 276

  • Slides: 12
Download presentation
Turtle Python Drawing Flags with Python J 276 2. 2

Turtle Python Drawing Flags with Python J 276 2. 2

Starter Load Thonny Type this program: Modify the program to draw your first name.

Starter Load Thonny Type this program: Modify the program to draw your first name.

Python Turtle ü Python Turtle is a "library" of Logo commands that we can

Python Turtle ü Python Turtle is a "library" of Logo commands that we can use with Python ü It lets us draw lines and simple shapes with Python and we can control the cursor position, line width etc. in our Python Program. 24/11/202 0 Horbury Academy ICT and Business Studies 3

Changing colour. Add this line to your script, near the start. Try using different

Changing colour. Add this line to your script, near the start. Try using different colours. Altogether, there are hundreds of colours, the best way to find them all is to try a colour and see if it works. 24/11/202 0 Horbury Academy ICT and Business Studies 4

Getting blocky You can create a filled shape with this program: Basically, start your

Getting blocky You can create a filled shape with this program: Basically, start your shape with begin_fill() and then use end_fill() at the end. Draw your name using filled shapes and different colours. 24/11/202 0 Horbury Academy ICT and Business Studies 5

Useful tip… You can make the turtle screen start near the top left with

Useful tip… You can make the turtle screen start near the top left with this command: setworldcoordinates(0, -400, 0) This will make the turtle start at the top left hand corner of your window. 24/11/202 0 Horbury Academy ICT and Business Studies 6

Polish Flag Draw the Polish Flag Remember to draw a black outline. Key skill:

Polish Flag Draw the Polish Flag Remember to draw a black outline. Key skill: Use two variables (width and height) to set the size of your flag 24/11/202 0 Horbury Academy ICT and Business Studies The Polish Flag 7

Two more tips… penup() and pendown() can be used to lift the pen up

Two more tips… penup() and pendown() can be used to lift the pen up whilst you move without making a line. setpos() can be used to move the turtle to a given position 24/11/202 0 Horbury Academy ICT and Business Studies 8

Functions • We often find that we need to do the same thing several

Functions • We often find that we need to do the same thing several times in a program. • Sometimes, we need to repeat the same code with only a small change between each time it is run. • We can do this with a function, which is also known as a subroutine. 24/11/202 0 Horbury Academy ICT and Business Studies 9

Function This function will draw a black border whenever you call it. The function

Function This function will draw a black border whenever you call it. The function is called with two parameters which we have called height and width. Functions must be defined at the start of your python program. 24/11/202 0 Horbury Academy ICT and Business Studies 10

More flags… Austria Netherlands Hungary Can you add a menu? Gabon 24/11/202 0 Germany

More flags… Austria Netherlands Hungary Can you add a menu? Gabon 24/11/202 0 Germany Horbury Academy ICT and Business Studies France 11

Repetition… With this flag (Greece), we could just repeat the same command, but we

Repetition… With this flag (Greece), we could just repeat the same command, but we should be making it more efficient by using a loop. You need to carefully analyse the flag. Try it… 24/11/202 0 Horbury Academy ICT and Business Studies 12