Turtle graphics with Python
Turtle is a Python library that allows programmers to create 2D graphics and animations by using a virtual turtle that can move around the screen. This library is commonly used in introductory programming courses to teach students about computer graphics and programming concepts.The turtle module provides a number of commands that can be used to move the turtle and draw shapes on the screen. These commands include forward, backward, right, left, and penup, pendown, which are used to control the turtle's movement and drawing.
The turtle module also allows the programmer to change the turtle's appearance by using functions such as shape and color. The turtle can be customized to have a different shape and color depending on the requirements of the program. In addition to these basic functions, the turtle module also provides features for animation and event handling.
These features can be used to create more complex programs that respond to user input or that animate graphics on the screen.
Overall, the turtle module is a useful tool for creating simple graphics and animations in Python. Its simplicity and ease of use make it a popular choice for beginners learning programming concepts. Additionally, its ability to create visual output can be helpful for visualizing data or creating simple games.
Turtle is python library, This library provided most of the feature like a drawing board, using this library we can create graphics,games,pictures and much more.
How to use turtle library in our program?
1. First you have to import turtle library
Source Code
import turtle
2. Create Object of the turtle
Source Code
t=turtle.Turtle()
If you aren't create the object of turtle,no problem but you have to write 'turtle.' before the any action, but it's make your code so long
Complete more than 10 turtle different shapes created in program
Source code
import turtle t=turtle.Turtle() t.speed(4500) t.color('cyan') t.screen.bgcolor('black') def circle(p): for i in range(75): t.circle(40) t.left(p) def square(tf,left,r): f=60 for i in range(r): t.fd(f) t.left(tf) t.fd(f) t.left(tf) t.fd(f) t.left(tf) t.fd(f) t.left(left) def spiral(left): for i in range(109): for color in ['white','cyan']: t.color(color) t.fd(i) t.left(left) def help(x,y): t.penup() t.goto(x,y) t.pendown() circle(10) help(-300,100) square(30,130,90) help(90,270) square(90,100,80) help(-90,-170) square(102,30,50) help(150,150) square(-30,200,80) help(-180,-150) square(45,301,100) help(-180,450) square(100,22,80) help(250,-200) square(302,13,90) help(300,450) spiral(30) help(-300,-520) spiral(50) help(0,-450) spiral(188) help(100,500) square(810,1,60) help(-290,230) square(-50,560,80) turtle.done()
CODE:
import turtle t=turtle.Turtle() t.speed(4500) t.color('cyan') t.screen.bgcolor('black') for i in range(75): t.circle(70) t.left(10) turtle.done()