python turtle库画BUCT中空
时间: 2023-12-25 07:30:04 浏览: 32
以下是使用Python的turtle库画一个BUCT中空的例子:
```python
from turtle import *
# 设置画布大小和背景颜色
setup(800, 600)
bgcolor("white")
# 设置画笔颜色和粗细
pensize(5)
pencolor("blue")
# 画字母B
penup()
goto(-200, 0)
pendown()
seth(90)
circle(50, 180)
circle(25, 180)
seth(-90)
circle(50, 180)
circle(25, 180)
# 画字母U
penup()
goto(-100, 0)
pendown()
seth(90)
circle(50, 180)
fd(100)
circle(50, 180)
# 画字母C
penup()
goto(0, 0)
pendown()
seth(90)
circle(50, 180)
circle(50, -180)
# 画字母T
penup()
goto(100, 0)
pendown()
seth(90)
fd(100)
seth(180)
fd(50)
seth(0)
fd(100)
# 结束绘制
hideturtle()
done()
```
相关问题
python turtle库画猪猪侠
好的,以下是Python Turtle库画猪猪侠的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("#fff")
# 画猪猪侠的头
turtle.penup()
turtle.goto(-70, 150)
turtle.pendown()
turtle.fillcolor("#fdd")
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 画猪猪侠的眼睛
turtle.penup()
turtle.goto(-40, 210)
turtle.pendown()
turtle.fillcolor("#000")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(40, 210)
turtle.pendown()
turtle.fillcolor("#000")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 画猪猪侠的鼻子
turtle.penup()
turtle.goto(0, 160)
turtle.pendown()
turtle.fillcolor("#fdd")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 画猪猪侠的嘴巴
turtle.penup()
turtle.goto(-40, 120)
turtle.pendown()
turtle.right(45)
turtle.circle(60, 90)
# 画猪猪侠的脸
turtle.penup()
turtle.goto(-170, -50)
turtle.pendown()
turtle.fillcolor("#fdd")
turtle.begin_fill()
turtle.circle(200)
turtle.end_fill()
# 画猪猪侠的耳朵
turtle.penup()
turtle.goto(-140, 170)
turtle.pendown()
turtle.fillcolor("#fdd")
turtle.begin_fill()
turtle.right(45)
turtle.circle(80, -90)
turtle.circle(40, -90)
turtle.end_fill()
turtle.penup()
turtle.goto(140, 170)
turtle.pendown()
turtle.fillcolor("#fdd")
turtle.begin_fill()
turtle.right(180)
turtle.circle(80, -90)
turtle.circle(40, -90)
turtle.end_fill()
# 画猪猪侠的身体
turtle.penup()
turtle.goto(-170, -50)
turtle.pendown()
turtle.fillcolor("#f00")
turtle.begin_fill()
turtle.right(45)
turtle.forward(50)
turtle.right(90)
turtle.circle(200, -180)
turtle.right(90)
turtle.forward(50)
turtle.end_fill()
# 画猪猪侠的腿
turtle.penup()
turtle.goto(-150, -200)
turtle.pendown()
turtle.fillcolor("#000")
turtle.begin_fill()
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(100)
turtle.end_fill()
turtle.penup()
turtle.goto(150, -200)
turtle.pendown()
turtle.fillcolor("#000")
turtle.begin_fill()
turtle.right(180)
turtle.forward(20)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(100)
turtle.end_fill()
# 画猪猪侠的手
turtle.penup()
turtle.goto(-250, 0)
turtle.pendown()
turtle.fillcolor("#fdd")
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.penup()
turtle.goto(250, 0)
turtle.pendown()
turtle.fillcolor("#fdd")
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示画布
turtle.done()
```
运行上述代码,即可在画布上看到猪猪侠的图案。
pythonturtle库画长方形
可以使用pythonturtle库中的forward()和left()方法来画长方形。具体实现代码如下:
```python
import turtle
# 创建画布
canvas = turtle.Screen()
# 创建画笔
pen = turtle.Turtle()
# 画长方形
for i in range(2):
pen.forward(100)
pen.left(90)
pen.forward(50)
pen.left(90)
# 关闭画布
canvas.exitonclick()
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](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)
![](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)
![](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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)