python使用海龟绘图画精美屈原人物图
时间: 2023-08-28 07:08:02 浏览: 99
好的,下面是一个用海龟绘图模块turtle画屈原人物图的Python代码:
```
import turtle
# 设置海龟的速度和画笔的颜色
turtle.speed(10)
turtle.pencolor("black")
# 画头部
turtle.circle(100)
# 画眼睛
turtle.penup()
turtle.goto(-40, 170)
turtle.pendown()
turtle.circle(20)
turtle.penup()
turtle.goto(40, 170)
turtle.pendown()
turtle.circle(20)
# 画嘴巴
turtle.penup()
turtle.goto(0, 130)
turtle.pendown()
turtle.circle(30, 180)
# 画身体
turtle.penup()
turtle.goto(-120, 0)
turtle.pendown()
turtle.circle(120, 180)
# 画裙子
turtle.penup()
turtle.goto(-150, -120)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("gray")
turtle.circle(150, 180)
turtle.end_fill()
# 画腿
turtle.penup()
turtle.goto(-100, -250)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("black")
turtle.forward(80)
turtle.right(90)
turtle.forward(150)
turtle.right(90)
turtle.forward(80)
turtle.right(90)
turtle.forward(150)
turtle.end_fill()
# 画鞋子
turtle.penup()
turtle.goto(-120, -250)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("gray")
turtle.forward(40)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(40)
turtle.right(90)
turtle.forward(20)
turtle.end_fill()
# 画手臂
turtle.penup()
turtle.goto(120, -50)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("black")
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(40)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(40)
turtle.end_fill()
# 画手
turtle.penup()
turtle.goto(120, -100)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("gray")
turtle.right(90)
turtle.forward(30)
turtle.right(90)
turtle.forward(60)
turtle.right(90)
turtle.forward(30)
turtle.right(90)
turtle.forward(60)
turtle.end_fill()
# 画月亮
turtle.penup()
turtle.goto(-200, 200)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor("white")
turtle.circle(40)
turtle.end_fill()
# 完成画图
turtle.done()
```
运行这段代码,就可以在海龟绘图窗口中看到屈原人物图了。如果需要保存图像,可以使用`turtle.getcanvas().postscript(file="filename.eps")`将图像保存为eps格式文件。
阅读全文