Tutorial Turtle in Python - Printable Version +- Red Security (https://redsecurity.info/cc) +-- Forum: Programming (https://redsecurity.info/cc/forumdisplay.php?fid=5) +--- Forum: Python (https://redsecurity.info/cc/forumdisplay.php?fid=9) +--- Thread: Tutorial Turtle in Python (/showthread.php?tid=7956) |
Turtle in Python - Covid-19 - 06-02-2022 Turtle: Hi guys, I hope you are doing well. Sorry for uploading late but I have brought you the most interesting thing about python. In this tutorial you will learn the turtle method which is I think the most interesting thing about python. It is used for generating graphics in python. It will give a great understanding of loops and if statements to beginners. So without wasting any time let’s just jump into the code directly. First of all we'll know how we can import turtle method in our program Code: import turtle This command will bring you turtle method in your program so first of all let’s create a square using turtle Code: import turtle So this is the most simple way of writing a code to make a square but we will discuss many more ways of drawing shapes. First of all let’s understand the code turtle.forward(100) means make a line of 100 pixels and turtle.left(90) means turn the pen 90 degrees towards left. So I am giving you a task to change only the values of the above code and see what happens. Now we will use input statements with turtle Code: import turtle Most interesting thing is using loops with the turtle so you can create the most attractive designs. Let’s first create a square using a loop and then we will jump into some advanced designs. Code: import turtle Loops are amazing, they make our task so easy so now let’s print some other designs.. Code: import turtle So as you can see I have just changed the values and the design is totally changed in this way you can create your design so easily. Code: # This program will draw any polygon for you depending on your input size Now I am going to create an advance design by changing values you should run it and see how it works Code: import turtle Here we use nested loops to create a design of polygon that looks like a flower. Now we will use turtle with a infinity loop Code: import turtle Printing star using turtle Code: from turtle import * You must be wondering why we use input() in the last part of the program if it is to wait until we see our pattern clearly. So that’s it for now before doing anything I suggest you to Quote: read the turtle documentation on python.org "Keep Good care of your Health Allah Hafiz and Good Bye Till the next post" |