Python Turtle Graphics – Patterns | Drawing Different Shapes

Python Turtle Graphics – Patterns | Drawing Different Shapes


Hello guys and welcome to Python Programming
tutorials by Amuls Academy, and i am back with another turtle tutorial .
In the previous turtle tutorial we discussed about up and down method that is how we can
control The Turtle, we can tell the turtle when to draw the line and when not to draw
the line while turtle is moving right?. From today onwards using all the methods we
learnt in the previous tutorials we will draw few patterns ok so we will begin with a simple
pattern that is this we want to draw five circles, first circle is this and we can see
4 more circles ok . so this will be the x coordinate and this
will be y coordinate and here I’ll take my own distance and radius ok.
so first to draw this pattern, to draw this circles what we need to do?, we need to import
the turtle module first right?, so in the Python file first step is import the turtle
module . next create a turtle object from the turtle
class alright . so now we will begin with this circle ok we
want to draw this circle first, so here we can see the center of the circle will be the
home position of the turtle ok so this will be the home position as well as this will
be the centre of the circle . and in my program i will take the radius of
circle is 50 ok if you want you can change that, but here I’ll take the radius as 50
in my program, if i save this and run this here we can see the turtle ok this is in the
home position. Now i want to draw a circle if i use circle
method then I’ll get the circle, but what will happen is, radius 50 and i told you right,
so if i save this and run this now ok it will draw from here from home position but in my
pattern i want the center of circle as the home position of The Turtle right?, I don’t
want to draw from here ok i want to draw from here .
so now what i need to do, i need to move this Turtle from here to here ok, so for that what
i will do is, before creating the circle i will use goto and I’ll move to the particular
position, that position is, ok here this will be the home position ok so i want to draw
Circle from here so i want this turtle here ok so for this what I’ll do is, i will use
goto method ok. I need to mention the x and y coordinates
where i want to move The Turtle so here what is this position, this is ok here we can see
ok so this is 0,0 home Position ok here x is 0, y is 0. now i want to move here OK what is this position?,
this is “minus y” ok if i take this, this is “minus x” ok so here “x is zero” right,
because it is present in the same line and y is this distance OK what is this distance
that is 50 ok so that is the radius of the circle and here I’ll take -50 because this
is “-y” . so i need to take -50 ok so here if i take
“0 and minus 50” ok so now if i save this and run this,
So turtle will move here and it will draw the circle but i don’t want this line right
here, so for that i need to use up and down. So before doing this, i need to do t.up, so
while moving to this position don’t draw the line, next after that i want line because
while drawing the circle i want line that’s why t.down ok. So now if i see this,
ok so now i got the first circle ok, so next in the circle we want to fill the color that
is green color right?, so to fill the color what we will use, we will use begin_fill,
end_fill and fill color right?, we already discussed about this so here before drawing
the circle, here i need to take begin fill so that is nothing but start filling so here
i need to mention the fill color here we want green right?, so I’ll mention green, next
after drawing circle end filling ok so now if i save this and run this done ok,
so done with the first circle ok so this is done . Next to draw this circle what I’ll do is,
now our turtle is here ok I’ll move it to home position ok so for that i will just use
t dot home ok it will move to the home position, if you want to see
ok here we can see . I don’t want this line so t.up, here you need
to use “t dot up” OK go to home right?, next here I’ll take the distance of this circle
from the home position is, I’ll take randomly ok, 200 200. x is 200 y coordinate is 200 ok .
if it is 200 200 ok both are positive because here positive y and positive x ok so both
are positive. so i need to go to this position and i need
to draw the circle ok so here what i will do is, I’ll copy this ok .
I am doing same thing , these are the code i used to draw circle right?, so I’ll copy
this and here I’ll paste this ok. so now i need to mention the distance, goto
200 200 right?, both are positive ok. next what i need to do, t.down next begin
fill, fill color here we can see the color is orange so here i will change that to Orange
ok, next draw a circle of 50 radius, end fill,t.up, go to home position. So now if i save this and run this
right?, done, Done with the second circle also. so now turtle is in the home position, now
i want to draw the circle ok, so for this also I’ll follow the same same piece of code,
but here we can see the distance if i take it is, it is also I’ll take 200 200 only ok
but here -x +y right?, the coordinates so here i need to take – 200 and 200 as the distance
ok coordinates ok . here -x and positive y, so here i will copy
this and i will paste this, so here -x ok so -200, 200, t.down and color is blue right?,
here we can see fill color is blue and the same code ok now again i will save this and
run this. ok so Done with the third circle also. So next thing is, we will go to here, this
circle ok the red circle, so here also the distance is 200 and 200 but here both are
negative -x, -y coordinate ok , so here -200, -200, so here we need to goto -200 -200 and
fill color is red, so i will copy and here i will paste. so -200 -200 , color is red Done.
ok so here we can see the distance is less right, compared to this upper part because
here we are drawing the circle in the anti clockwise direction right?, so when i take
distance as 200 and 200 here it comes ok this point, and it will draw circle like this ok
but here it is 200 and 200 it will come here ok, so it will draw circle like this that’s
why the distance is less ok, now i want the last circle ok so here the distance is 200
200, but here -y and positive x, ok so 200 and -200 alright, color is yellow . Ok so we got the same pattern because here
distance is different, these two has more distance from the home position, and these
two has less,because of that direction ok, so if i take here -50 and here -50 it will
draw in the clockwise and we will get the same distance if you want to see,
look now distance is same right?, ok. so next so here we can see this program is
very lengthy ok so instead of writing this code again and again ok so here codes are
Repeating right?, lines are repeating, so instead of doing this we can define a function
and we can put this code in that function and we can call that function whenever we
want right?, so we can do that, so for that what i need to do is, here, here I’ll take
def, I’ll define a function, you can give any name to this function I’ll give as “draw
circle”, ok because we are drawing the circle ok so here i need to take few parameters so
the first thing is here we can see in every code, change is one is this coordinates right?,
we want to go to different position ok. Here we can see, so what I’ll do is, I’ll
take x and y ok so we can ask the user to mention that and as well as color the color
of each circle is different so color and next i will take radius also, because here in the
last part we took -50 right?, we want to draw circle in the anticlockwise direction also
so that’s why Ok. I will take radius as rad so now what i will
do is, i will copy this , this code and i will put it inside the function. Ok here first i will define the function and
next here i will take this. ok and here instead of this goto i need to
mention x,y and here color and here radius ok done. so next here instead of this code i can call
this function now that is draw circle, first 0 – 50, color is green,radius is positive
50, done ok so now i don’t want this, i can delete this. so now instead of this i can write draw circle,
here coordinate is 200 200, color is orange, radius is 50, now i can delete this. Now again for this i will copy this ok distance
is -200 200, color is blue and radius is 50 ok so i don’t want this. Again paste ok so distance is – 200, – 200
color is red and radius is -50 , done i don’t want this now. so now again 200 and -200, color is yellow
and radius is -50, I don’t want this now ok. so now we can see it contains only few lines
this program right?, so now if i save this and run this ok.
so in this way we can use functions here. so here what I’ll do is, i will again include
few function ok, here I’ll take it as, 0 300 I’ll include few function call more that’s
it . Ok so like this you can do many patterns here. And one more thing you can increase the pen
size also ok here you can go for t.pensize and you can mention ok 10,20, or 2,3,4 ok
so if i go for 4, here we can see the line thickness ok now
it is dark right?, the thickness is more like here ok so in this way you can draw the lines
if you want you can increase the speed also ok so this is about the pattern. ok so i know this is the simple pattern but
first we need to know how to use the method how to use the function and all right?, so
that’s why i made this video, i hope this video will help you and that’s it for now
guys thank you for watching don’t forget to subscribe to my channel I will meet you in
next class till then take care.

Randy Schultz

Related Posts

14 thoughts on “Python Turtle Graphics – Patterns | Drawing Different Shapes

  1. Zahid Toofani says:

    Very nice
    Thanku very much, having a nice session.

  2. Nagoor Shaik says:

    Thank u …amulya..have a wonderful explain to us

  3. san k says:

    pickle ,decorator andha maari topic podungaadam

  4. Saqib khanz says:

    Ma'am tell me about (-50). And uploaded such type of video.

  5. ARIF ANWER says:

    Ossam mam recently I starting your videos great explanation mam…

  6. Royal Zaheerabadiz says:

    your teaching style is best

  7. neelanshu agarwal says:

    i wrote the same first two lines and run them it shows error. AttributeError. Like module turtle has no attribute Turtle. Please solve it soon

  8. Prince Chauhan says:

    thank you

  9. neelanshu agarwal says:

    we have to download python turtle graphics software to run turtle??

  10. Nitin Dabas says:

    Please make the video on bouncing balls with turtle

  11. Enes Dogan says:

    10000times okey ??

  12. Dipesh Rathva says:

    Awesome tricks i like ur tutorials and its very interesting

  13. Bhargav Ratnala says:

    how to highlights output by changing the colour

  14. samuel barry says:

    And the first one should be well centred t.goto(5, 0)

    In order to get right in the middle. Try it.

Leave a Reply

Your email address will not be published. Required fields are marked *