What is Python Turtle?
Turtle graphics is a popular way for introducing programming to kids. It was part of the original Logo programming language developed by Wally Feurzeig, Seymour Papert and Cynthia Solomon in 1967.Imagine a robotic turtle starting at (0, 0) in the x-y plane. After an import turtle, give it the command turtle.forward(15), and it moves (on-screen!) 15 pixels in the direction it is facing, drawing a line as it moves. Give it the command turtle.right(25), and it rotates in-place 25 degrees clockwise.
import turtle#pip install PythonTurtle{codeBox}
By combining together these and similar commands, intricate shapes and pictures can easily be drawn.
The turtle module is an extended re-implementation of the same-named module from the Python standard distribution up to version Python 2.5.
It tries to keep the merits of the old turtle module and to be (nearly) 100% compatible with it. This means in the first place to enable the learning programmer to use all the commands, classes and methods interactively when using the module from within IDLE run with the -n switch.
The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses tkinter for the underlying graphics, it needs a version of Python installed with Tk support.
Find below full code and live demo video.
Please find below script:
import turtle#pip install PythonTurtlepen = turtle.Turtle()#create turtel objectdef curve():#define method to draw curvefor i in range(200):#define step by step curve motionpen.right(1)pen.forward(1)def heart():#define method to draw heartpen.fillcolor('red')#set fill colorpen.begin_fill()#start filling the colorpen.left(140)#draw left linepen.forward(113)curve()#draw the curvepen.left(120)#draw the right linecurve()#draw the curvepen.forward(112)pen.end_fill()#end filling the colorheart()#call the heart methodturtle.exitonclick()#to close graphics window on click#Let's run this...{codeBox}
Comment below if you have any question....
0 Comments