编写程序导入 turt1e 库,并画出如图所示的等边三角形。最外面三角形边长为 200,三边颜色为红色,次外面的三角形边长为 10日,三边颜色为蓝色,填充颜色为黄色:最里面的三角形三边长度为 5日,颜色为红色,填充颜色为白色。
时间: 2024-03-03 07:47:08 浏览: 45
好的,以下是 Python 代码:
```python
import turtle
# 创建画布
canvas = turtle.Screen()
canvas.bgcolor("white")
# 创建画笔
pen = turtle.Turtle()
pen.speed(0)
# 最外面的三角形
pen.color("red")
pen.pensize(3)
pen.goto(0, -100)
pen.begin_fill()
for i in range(3):
pen.forward(200)
pen.left(120)
pen.end_fill()
# 次外面的三角形
pen.color("blue")
pen.pensize(2)
pen.goto(0, -90)
pen.begin_fill()
for i in range(3):
pen.forward(100)
pen.left(120)
pen.end_fill()
# 最里面的三角形
pen.color("red")
pen.pensize(1)
pen.goto(0, -80)
pen.begin_fill()
for i in range(3):
pen.forward(15)
pen.left(120)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
# 显示画布
turtle.done()
```
运行后,会弹出一个窗口显示这个图形。
相关问题
使用turt1e库的turtle. right()函数和turtle. fd()函数绘制一个菱形,边长为200像素, 4个内角度数为2个60度和2个120度。
好的,以下是使用turtle库绘制菱形的代码:
```
import turtle
# 创建turtle对象
t = turtle.Turtle()
# 设置笔的粗细和颜色
t.pensize(2)
t.pencolor('blue')
# 绘制菱形
for i in range(2):
t.fd(200)
t.right(60)
t.fd(200)
t.right(120)
# 关闭窗口
turtle.done()
```
解释一下代码:首先我们创建了一个`turtle`对象,然后设置了笔的粗细和颜色。接着使用`for`循环绘制了菱形的4条边,每条边的长度都是200像素,内角分别为2个60度和2个120度。最后使用`turtle.done()`关闭窗口。
使用turtle库的turtle.fd()函数和turt1e.seth()函数绘制一个每方向为100像素长度的十字形。
好的,以下是使用turtle库绘制十字形的代码:
```
import turtle
# 创建turtle对象
t = turtle.Turtle()
# 设置笔的粗细和颜色
t.pensize(2)
t.pencolor('red')
# 绘制十字形
for i in range(4):
t.fd(100)
t.penup()
t.backward(100)
t.pendown()
t.seth(t.heading() + 90)
# 关闭窗口
turtle.done()
```
解释一下代码:首先我们创建了一个`turtle`对象,然后设置了笔的粗细和颜色。接着使用`for`循环绘制了十字形的四条边,每条边的长度都是100像素。在每次绘制完一条边之后,我们抬起笔、后退100像素、再放下笔,然后旋转90度,准备绘制下一条边。最后使用`turtle.done()`关闭窗口。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![apk](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)