Coding with Python IDE (Pydroid 3) "Lecture day 2" - The Turtle Module of Python
Hello Friends |
---|
In my previous class, I told us why I love coding with Python, and I went further to tell us about a module in the Python library called Turtle, where we can import and design beautiful animations easily.
The turtle module of Python is very interesting, especially when you begin to create amazing designs and logos. For this week lecture, I will be showing you the basic commands and their functions in a turtle module. With this basic commands, you can direct the turtle on what to do, whereby creating something really simple and attractive.
So in this class we will be designing 2 objects, and I would be releasing the codes of my design to my students.
For the first part of our design today, we will be writing the code to design the image of a virus.
- Remember the first step is always to import the turtle module. I then set my background color as black which is represented in code as bg color("black").
And I used ht() to hide the turtle pen and make it invisible.
I then proceeded into giving the instructions for my design, where I assigned heading to begin at -90, and speed at 30.
From line 8 of my code, I instructed my design on how to display by given it a color and a pattern of movement which is represented as fd(i * 3)
The second design for today is the logo of Facebook, and to begin with, we import turtle as usual, I then define the def function for both left (l) and right(r) as y and x.
From 10th line of my code, I decided to to first design a blue and fill a blue round circle. To perform this, I insert blue as color, and I then inserted my desired width of the circle (3).
The blue filling was assigned to start and end between the radius of 140 and 360.
So it's time to carve out the F-like shape from our turtle,, and we know it's fill color is white.
So all I did from line 23 - 39 was to instruct the turtle on how to move **left, right, forward, and circle within a specified distance as seen in the brackets(). I ended the fill and my code was done. And the program was successfully running.
I will be sharing the codes of our above tasks today, for those interested in trying it out. And most importantly I will be equally sharing a bonus code as requested by a friend @fantvwiki.
1st object to Design(Image of a Virus) | Source Code |
---|
from turtle import *
bgcolor("black")
ht()
bk(180)
setheading(-90)
speed(30)
for i in range(180):
color("blue")
lt(i)
fd(i * 3)
color("red")
lt(i)
fd(i * 3)
done()
2nd object to Design(Facebook logo) | Source Code |
---|
from turtle import *
def l(y,x):
lt(y)
fd(x)
def r(y,x):
rt(y)
fd(x)
color("pblue")
width(3)
ht()
begin_fill()
circle(140,360)
end_fill()
rt(7)
bk(32)
color("white")
begin_fill()
l(97,98)
l(90,40)
r(90,40)
r(90,40)
l(90,34)
circle(-45,90)
fd(40)
r(90,40)
r(90,20)
circle(17,90)
fd(23)
l(90,40)
r(100,40)
r(80,30)
l(90,110)
r(90,50)
end_fill()
done()
Bonus object to Design(I ❤️ U Steemit) | Source Code |
---|
import turtle
st = turtle.Turtle()
turtle.Screen().bgcolor("green")
st.penup()
st.goto(-220,155)
st.pendown()
st.pencolor('white')
st.pensize(13)
st.forward(97)
st.backward(47)
st.right(90)
st.forward(166)
st.right(90)
st.forward(47)
st.backward(97)
st.penup()
st.goto(0,0)
st.pendown()
st.color("red")
st.begin_fill()
st.right(127)
st.forward(130)
st.circle(50,200)
st.right(137)
st.circle(50,200)
st.forward(130)
st.end_fill()
st.penup()
st.setpos(137, 170)
st.pendown()
st.pencolor("white")
st.right(40)
st.forward(120)
st.circle(57,170)
st.forward(120)
st.penup()
st.goto(-145,-145)
st.pendown()
st.color('white')
st.write("steemit by @preye2", font=("Courier",11,"bold"))
Conclusion |
---|
This will surely be an interesting journey friends, as I have lots of wonderful and interesting designs to teach us in this class using python. I guess they might be some challenges and questions regarding this class you might want to ask, feel free to drop them on the comment section.
Cc:
Note: All pictures and screenshots were taken and edited by me using iMarkup.
Happy Steeming lovelies❤
Shared on Facebook
good friend, the tutorial is easy to learn for beginners, even children may find it easy to understand this to learn with the pictures generated from a simple coding process.
Thanks for your constructive and educative feedback my friend, it's comments like this that keeps us going. Your time here is highly appreciated ❤️.
yes I like good content, informative, steemit has a little good content, mostly all garbage.
Honestly, friend I must say that your tutorial has taught me a lot. In this particular tutorial I have come to understand a lot of this. Keep it up and thank you for mentioning me.
Am really glad and excited that this lecture was impactful to you sir. I would surely come up with even more interesting tutorials. Thanks alot for your time and remark here, I really appreciate ❤️.
Nice! As someone of "a certain age", I vividly remember doing Turtle graphics on the BBC Model B computer -- complete with a physical Turtle robot with a pen:
(Image source)
Amazing and interesting I must commend😲, turtle graphics using the LOGO programming language🤔 you must have really been programming from childhood.
Respect sir🙌
Should I say ya gifted??
Nooo that's an understatement, you're talented and simply amazing, you see all what you wrote.... nothing have stuck so far
Please teach me on Whatsapp
09078182444🙏
Preshy my most serious student, your remark is inspiring hun, and this is the encouragement I need. Thanks for your time here dearie. I will sure do more explaining on your DM.
Link to my WhatsApp 👇👇
http://wa.me/+2349026068443
Alternatively my Facebook link
https://www.facebook.com/preye.amaran.50
Curated By - @simonnwigwe
Curation Team - Team 3
Thank you dear.