python代码画人物
以下是一个使用Python绘制人物的示例代码:
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 创建画笔
pen = turtle.Turtle()
# 设置画笔颜色和粗细
pen.color("black")
pen.pensize(3)
# 绘制头部
pen.circle(100)
# 绘制眼睛
pen.penup()
pen.goto(-40, 120)
pen.pendown()
pen.circle(10)
pen.penup()
pen.goto(40, 120)
pen.pendown()
pen.circle(10)
# 绘制嘴巴
pen.penup()
pen.goto(-40, 90)
pen.pendown()
pen.setheading(-60)
pen.circle(40, 120)
# 绘制身体
pen.penup()
pen.goto(-100, -100)
pen.pendown()
pen.setheading(-90)
pen.forward(200)
# 绘制手臂
pen.penup()
pen.goto(-100, 0)
pen.pendown()
pen.setheading(-135)
pen.forward(100)
pen.penup()
pen.goto(-100, 0)
pen.pendown()
pen.setheading(-45)
pen.forward(100)
# 绘制腿
pen.penup()
pen.goto(-100, -200)
pen.pendown()
pen.setheading(-135)
pen.forward(100)
pen.penup()
pen.goto(-100, -200)
pen.pendown()
pen.setheading(-45)
pen.forward(100)
# 隐藏画笔
pen.hideturtle()
# 关闭画布
turtle.done()
运行以上代码,将会在窗口中绘制一个简单的人物形象。你可以根据需要修改代码来绘制不同的人物形象。
当然,还可以根据需要继续补充代码来绘制更复杂的人物形象。以下是一个绘制小人的示例代码:
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 创建画笔
pen = turtle.Turtle()
# 设置画笔颜色和粗细
pen.color("black")
pen.pensize(3)
# 绘制头部
pen.circle(50)
# 绘制眼睛
pen.penup()
pen.goto(-20, 60)
pen.pendown()
pen.circle(5)
pen.penup()
pen.goto(20, 60)
pen.pendown()
pen.circle(5)
# 绘制嘴巴
pen.penup()
pen.goto(-25, 40)
pen.pendown()
pen.setheading(-60)
pen.circle(25, 120)
# 绘制身体
pen.penup()
pen.goto(0, -50)
pen.pendown()
pen.setheading(-90)
pen.forward(100)
# 绘制手臂
pen.penup()
pen.goto(0, 0)
pen.pendown()
pen.setheading(-135)
pen.forward(50)
pen.penup()
pen.goto(0, 0)
pen.pendown()
pen.setheading(-45)
pen.forward(50)
# 绘制腿
pen.penup()
pen.goto(0, -100)
pen.pendown()
pen.setheading(-135)
pen.forward(50)
pen.penup()
pen.goto(0, -100)
pen.pendown()
pen.setheading(-45)
pen.forward(50)
# 绘制帽子
pen.penup()
pen.goto(-50, 80)
pen.pendown()
pen.setheading(0)
pen.forward(100)
pen.penup()
pen.goto(-50, 80)
pen.pendown()
pen.setheading(-90)
pen.forward(20)
# 隐藏画笔
pen.hideturtle()
# 关闭画布
turtle.done()
运行以上代码,将会在窗口中绘制一个小人形象,包括头部、眼睛、嘴巴、身体、手臂、腿和帽子。你可以根据需要修改代码来绘制不同的人物形象。