Asked by axel

Write a program that will draw 7 shapes.
Your shapes should:

Start with 0 points
Each increase the number of points by 1 (ie: line- 2 points, triangle- 3 points, square- 4 points, etc.)
Start with a radius of 20 and increase in radius by 20 pixels each time
All be drawn from the same starting position
Initialize Tracy’s starting position using: setposition(0, -150)
Hint: It may be difficult to control both the radius of the shape and the number of points with the value of i. You may want to use a separate variable called radius to control the radius of the shape.

Answers

Answered by GPT-4o mini
To create a program that draws 7 shapes with the specifications given, we can use the Python turtle graphics library. The shapes will start with 0 points and increase the number of points by 1 for each shape drawn. Additionally, the radius will start at 20 pixels and increase by 20 pixels for each shape.

Here’s an implementation that does that:

```python
import turtle

# Set up the screen and turtle
screen = turtle.Screen()
tracy = turtle.Turtle()

# Function to draw a shape with a specified number of points and radius
def draw_shape(sides, radius):
angle = 360 / sides
for _ in range(sides):
tracy.forward(radius)
tracy.left(angle)

# Initialize starting position
tracy.setposition(0, -150)

# Draw shapes; number of points starts at 2 and increases up to 8
for i in range(2, 9): # from 2 points (line) to 8 points (octagon)
radius = i * 20 # radius increases by 20 pixels for each shape
draw_shape(i, radius) # Draw the shape with the current number of points and radius
tracy.penup() # Lift the pen to move without drawing
tracy.setposition(0, tracy.ycor() + 50) # Move up for the next shape
tracy.pendown() # Put the pen down to draw the next shape

# Hide the turtle and finish
tracy.hideturtle()
turtle.done()
```

### Explanation of the Code:

1. **Setup**:
- We import the `turtle` module and create a screen and a turtle named `tracy`.

2. **Function `draw_shape`**:
- This function takes the number of sides (or points) and the radius as parameters.
- It calculates the angle to turn for each point and uses a loop to draw the shape with the specified number of points.

3. **Starting Position**:
- Tracy's starting position is set at `(0, -150)`.

4. **Drawing Shapes**:
- A loop runs from 2 to 8 (to create shapes with 2 to 8 points).
- For each shape, the radius is calculated as `i * 20`, where `i` is the current number of sides.
- The `draw_shape` function is called to draw the current shape.
- After drawing a shape, Tracy moves up by 50 pixels for the next shape without drawing (using `penup` and `pendown`).

5. **Completion**:
- Finally, we hide the turtle and call `turtle.done()` to complete the drawing.

You can run the above code in any Python environment with the `turtle` module available, such as IDLE or any script-based environment that supports it.
There are no human answers yet. A form for humans to post answers is coming very soon!

Related Questions