Below is a Python program that uses the turtle
graphics library to draw seven shapes. Each shape will have an increasing number of points and an increasing radius, starting from 20
pixels. The program will start drawing from the position (0, -150)
.
Make sure you have the turtle
library installed and use Python environment to run the program.
import turtle
# Function to draw a shape with a specified number of points and radius
def draw_shape(points, radius):
angle = 360 / points
turtle.penup()
turtle.setposition(0, -150) # Starting position
turtle.pendown()
turtle.pencolor("black")
turtle.fillcolor("lightblue")
turtle.begin_fill()
for _ in range(points):
turtle.forward(radius)
turtle.left(angle)
turtle.end_fill()
turtle.penup()
turtle.right(angle) # Reset orientation for the next shape
turtle.forward(radius + 10) # Move forward to avoid overwriting shapes
# Initialize turtle
turtle.speed(2) # Set the drawing speed
turtle.pensize(2) # Set the pen size
# Draw 7 shapes
for i in range(1, 8): # Draw shapes from 1 to 7 points
radius = 20 * i # Increase radius by 20 pixels for each shape
draw_shape(i, radius) # Draw shape with `i` points and current radius
turtle.hideturtle() # Hide the turtle cursor
turtle.done() # Finish drawing
Explanation:
-
Function
draw_shape(points, radius)
: This function draws a shape based on the number of points and radius provided.- It calculates the angle for each corner of the shape using
360 / points
. - The turtle moves forward by the length of the
radius
and turns by the calculated angle to create the shape.
- It calculates the angle for each corner of the shape using
-
Main Loop:
- The loop iterates from
1
to7
, representing the number of points for each shape. - The radius of each subsequent shape increases by
20
pixels.
- The loop iterates from
-
Turtle Setup: The drawing starts from the position
(0, -150)
, and the drawing speed and pen size can be adjusted as needed.
Run the Code:
Make sure to run this code in an environment that supports turtle graphics, such as a local Python installation with a GUI, because turtle graphics may not function in some online interpreters.