用turtle库画沈阳药科大学
时间: 2023-10-08 18:06:29 浏览: 157
好的,让我来展示一下使用turtle库画沈阳药科大学的过程。
首先,我们需要导入turtle库和time库,代码如下:
```python
import turtle
import time
```
接下来,我们需要设置画布的大小和背景颜色,代码如下:
```python
turtle.setup(800, 600)
turtle.bgcolor("#F7F7F7")
```
然后,我们可以定义一个函数来画出沈阳药科大学的主楼和附楼,代码如下:
```python
def draw_building():
# 画主楼
turtle.penup()
turtle.goto(-200, 0)
turtle.pendown()
turtle.setheading(90)
turtle.pensize(3)
turtle.pencolor("#003366")
turtle.fillcolor("#003366")
turtle.begin_fill()
for i in range(2):
turtle.forward(200)
turtle.right(90)
turtle.forward(300)
turtle.right(90)
turtle.end_fill()
# 画附楼
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.setheading(90)
turtle.pensize(3)
turtle.pencolor("#003366")
turtle.fillcolor("#003366")
turtle.begin_fill()
for i in range(2):
turtle.forward(200)
turtle.right(90)
turtle.forward(150)
turtle.right(90)
turtle.end_fill()
# 写字
turtle.penup()
turtle.goto(-280, -50)
turtle.pendown()
turtle.write("沈阳药科大学", font=("Microsoft YaHei", 24, "bold"))
```
最后,我们可以调用这个函数来画出沈阳药科大学,代码如下:
```python
draw_building()
time.sleep(3)
```
完整代码如下:
```python
import turtle
import time
def draw_building():
# 画主楼
turtle.penup()
turtle.goto(-200, 0)
turtle.pendown()
turtle.setheading(90)
turtle.pensize(3)
turtle.pencolor("#003366")
turtle.fillcolor("#003366")
turtle.begin_fill()
for i in range(2):
turtle.forward(200)
turtle.right(90)
turtle.forward(300)
turtle.right(90)
turtle.end_fill()
# 画附楼
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.setheading(90)
turtle.pensize(3)
turtle.pencolor("#003366")
turtle.fillcolor("#003366")
turtle.begin_fill()
for i in range(2):
turtle.forward(200)
turtle.right(90)
turtle.forward(150)
turtle.right(90)
turtle.end_fill()
# 写字
turtle.penup()
turtle.goto(-280, -50)
turtle.pendown()
turtle.write("沈阳药科大学", font=("Microsoft YaHei", 24, "bold"))
turtle.setup(800, 600)
turtle.bgcolor("#F7F7F7")
draw_building()
time.sleep(3)
```
运行代码,就可以看到画出的沈阳药科大学了。
阅读全文