How to Draw Circles Using Python Turtle
Python contains an interesting drawing module called Turtle. This module is available as part of the standard python distribution. Turtle consists of a number of graphics operations modelled after pen drawing. In this article I will show you how we can use the turtle commands to draw circle based shapes.
How to Draw a Simple Circle Using Python Turtle
The following python script creates a simple circle with default color at the center of the turtle canvas. We have defined the turtle canvas with a width of 800 pixels and a height of 600 pixels. We then draw a circle of radius 100 pixels in the middle of the canvas. Note that the bottom of the circle is placed in the middle of the canvas.
import turtle turtle.setup(800,600) board = turtle.Turtle() board.penup() board.setpos(0,0) board.pendown() board.circle(100) turtle.done()
How to Draw a Face Using Python Turtle
The following python script draws the shape of a face using the turtle commands. We have organized the code in functions so that each section of the drawing is separate. Note that we are resetting the direction of the pen after drawing part of a circle in the draw_lip functions.
import turtle turtle.setup(800,600) board = turtle.Turtle() def draw_face(): board.penup() board.setpos(0,0) board.pendown() board.circle(100) def draw_left_eye(): board.penup() board.setpos(-50,100) board.pendown() board.circle(25) def draw_right_eye(): board.penup() board.setpos(50,100) board.pendown() board.circle(25) def draw_right_lip(): board.penup() board.setpos(0,25) board.pendown() board.circle(100,45) board.setheading(0) def draw_left_lip(): board.penup() board.setpos(0,25) board.pendown() board.circle(100,-45) board.setheading(0) draw_face() draw_left_eye() draw_right_eye() draw_left_lip() draw_right_lip() board.penup() board.setpos(400,400) turtle.done()
How to Draw Tangent Circles Using Python Turtle
The following python program creates tangent circles at the middle of the canvas. We use a loop to generate the circles and for each iteration we just change the radius of the circle.
import turtle turtle.setup(800,600) board = turtle.Turtle() for i in range(1,20): board.circle(i*10) turtle.done()
How to Draw Concentric Circles Using Python Turtle
The following python program creates concentric circles at the middle of the canvas. We use a loop to generate the circles and for each iteration we change the y location and the radius of the circle.
import turtle turtle.setup(800,600) board = turtle.Turtle() for i in range(1,20): board.circle(i*10) board.penup() board.sety(-i*10) board.pendown() turtle.done()
How to Draw Olympics Logo Using Python Turtle
The following python program creates the olympics logo using the the turtle package. It also demonstrates the use of pen color and pen size in drawing shapes.
import turtle turtle.setup(800,600) board = turtle.Turtle() circle_positions = [(-120,0,"blue"), (0,0,"black"), (120,0,"red"), (-60,-60,"yellow"), (60,-60,"green")] for pos in circle_positions: board.penup() board.setpos(pos[0],pos[1]) board.pencolor(pos[2]) board.pensize(5) board.pendown() board.circle(50) turtle.done()