Coding with Python IDE (Pydroid 3) "Lecture day 2" - The Turtle Module of Python

in Steem Marketing2 years ago (edited)
Hello Friends

png_20220920_075711_0000.png
Designed on Canva

3W72119s5BjVs3Hye1oHX44R9EcpQD5C9xXzj68nJaq3Ce9uQQWaq8TayYVimHWnwFBRcHh1usaB4uBpk5RrULLx6wnZ5nRt1g3BbD9YiTjeiGQwxjmvzA.png

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.

3W72119s5BjVs3Hye1oHX44R9EcpQD5C9xXzj68nJaq3Ce9uQQWaq8TayYVimHWnwFBRcHh1usaB4uBpk5RrULLx6wnZ5nRt1g3BbD9YiTjeiGQwxjmvzA.png

3W72119s5BjVs3Hye1oHX44R9EcpQD5C9xXzj68nJaq3Ce9uQQWaq8TayYVimHWnwFBRcHh1usaB4uBpk5RrULLx6wnZ5nRt1g3BbD9YiTjeiGQwxjmvzA.png

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)

3W72119s5BjVs3Hye1oHX44R9EcpQD5C9xXzj68nJaq3Ce9uQQWaq8TayYVimHWnwFBRcHh1usaB4uBpk5RrULLx6wnZ5nRt1g3BbD9YiTjeiGQwxjmvzA.png


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.


3W72119s5BjVs3Hye1oHX44R9EcpQD5C9xXzj68nJaq3Ce9uQQWaq8TayYVimHWnwFBRcHh1usaB4uBpk5RrULLx6wnZ5nRt1g3BbD9YiTjeiGQwxjmvzA.png

Below are some of the source codes to our tasks today

3W72119s5BjVs3Hye1oHX44R9EcpQD5C9xXzj68nJaq3Ce9uQQWaq8TayYVimHWnwFBRcHh1usaB4uBpk5RrULLx6wnZ5nRt1g3BbD9YiTjeiGQwxjmvzA.png

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()

3W72119s5BjVs3Hye1oHX44R9EcpQD5C9xXzj68nJaq3Ce9uQQWaq8TayYVimHWnwFBRcHh1usaB4uBpk5RrULLx6wnZ5nRt1g3BbD9YiTjeiGQwxjmvzA.png


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()

3W72119s5BjVs3Hye1oHX44R9EcpQD5C9xXzj68nJaq3Ce9uQQWaq8TayYVimHWnwFBRcHh1usaB4uBpk5RrULLx6wnZ5nRt1g3BbD9YiTjeiGQwxjmvzA.png


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"))

3W72119s5BjVs3Hye1oHX44R9EcpQD5C9xXzj68nJaq3Ce9uQQWaq8TayYVimHWnwFBRcHh1usaB4uBpk5RrULLx6wnZ5nRt1g3BbD9YiTjeiGQwxjmvzA.png

Conclusion

3W72119s5BjVs3Hye1oHX44R9EcpQD5C9xXzj68nJaq3Ce9uQQWaq8TayYVimHWnwFBRcHh1usaB4uBpk5RrULLx6wnZ5nRt1g3BbD9YiTjeiGQwxjmvzA.png

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❤

Sort:  
 2 years ago 

Shared on Facebook

Screenshot_20220920-084047_1.png

 2 years ago 

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.

 2 years ago 

Thanks for your constructive and educative feedback my friend, it's comments like this that keeps us going. Your time here is highly appreciated ❤️.

 2 years ago 

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.

 2 years ago 

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:

turt
(Image source)

 2 years ago 

Amazing and interesting I must commend😲, turtle graphics using the LOGO programming language🤔 you must have really been programming from childhood.
Respect sir🙌

Loading...
 2 years ago 

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🙏

 2 years ago 

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.

 2 years ago 

Link to my WhatsApp 👇👇

http://wa.me/+2349026068443

Alternatively my Facebook link
https://www.facebook.com/preye.amaran.50

Congratulations! This post has been upvoted through steemcurator06.

Curated By - @simonnwigwe

Curation Team - Team 3

 2 years ago 

Thank you dear.

Coin Marketplace

STEEM 0.24
TRX 0.12
JST 0.029
BTC 67447.76
ETH 3523.98
USDT 1.00
SBD 3.11