turtle绘制小人
import turtle
turtle.setup(700,700,100,100)#setup()设置窗体大小,后两个参数可选,该函数也不是必须的
turtle.speed(10)#设置画笔移到速度,参数值为0-10,数字越大,速度越大
turtle.pensize(10)#设置画笔尺寸大小
turtle.pencolor(‘green‘)#设置画笔颜色
turtle.penup()#将画笔抬起(抬起时移到画笔将不会在画布留下痕迹)
turtle.goto(0,190)#将画笔移到(x,y)
turtle.pendown()#将画笔落下
turtle.circle(80,360)#画圆,半径为正表示圆心在画笔左边
turtle.fillcolor(‘yellow‘)
turtle.penup()
turtle.goto(-20,250)
turtle.seth(-90)#改变海龟行进方向,但不行进,属于绝对角度
turtle.pendown()
turtle.circle(20,180)
turtle.penup()
turtle.goto(-10,280)
turtle.pendown()
turtle.circle(20,180)
turtle.penup()
turtle.goto(50,280)
turtle.left(180)#tuetle.left() turtle.right() 可以改变海龟行进角度,属于相对角度,left逆时针移到角度,right顺时针移到角度
turtle.pendown()
turtle.circle(20,180)
turtle.penup()
turtle.goto(-25,195)
turtle.pendown()
turtle.fd(25)#画笔向前移到距离
turtle.left(90)
turtle.fd(50)
turtle.left(90)
turtle.fd(25)
turtle.penup()
turtle.goto(-90,170)
turtle.left(180)
turtle.down()
for i in range(1,5):
if i%2!=0:
turtle.fd(200)
else:
turtle.fd(180)
turtle.left(90)
for i in [-90,90]:
turtle.penup()
turtle.goto(i,120)
if i==-90:
turtle.right(90)
else:
turtle.left(180)
turtle.down()
turtle.fd(25)
turtle.left(90)
turtle.fd(180)
turtle.right(90)
turtle.circle(15)
turtle.penup()
turtle.goto(-60,-30)
turtle.right(90)
turtle.pendown()
turtle.fd(200)
turtle.left(90)
turtle.fd(25)
turtle.penup()
turtle.goto(60,-30)
turtle.right(90)
turtle.pendown()
turtle.fd(200)
turtle.right(90)
turtle.fd(25)
turtle.penup()
turtle.hideturtle()#隐藏画笔
#turtle.showturtle()#显示画笔
turtle.bk(100)#向后移到画笔
turtle.pencolor(‘red‘)
turtle.dot(100)#绘制一个半径为r的原点
结果如下
原文地址:https://www.cnblogs.com/gzk08-20/p/9215982.html
时间: 2024-10-12 04:55:19