海归画图turtle()

1.画布

1. 设置画布大小

#1.........................................................
turtle.screensize(canvwidth=None, canvhigth=None, bg=None)  #参数分别为画布的宽, 高, 背景颜色
turtle.screensize()                         #默认值为:(400,300)
#2.........................................................
turtle.setup(width=0.5, height=0.5,startx=None,starty=None)  #weidth,height为小数时,表示画布占电脑屏幕的比例,为整数时,表示像素,(startx,starty)表示窗口距离屏幕左上角的位置,如果为None,则位于屏幕中心

2. 画笔

#1......................................
turtle.pensize()               #设置笔的宽度
turtle.pencolor()              #设置笔的颜色
turtle.speed()                 #笔移动速度

3. 画笔运动命令

命令 说明
turtle.forward(diatance) 向当前画笔方向移动distance像素的长度
turtle.background(distance) 向当前画笔相反方向移动distance像素的长度
turtle.right(degree) 顺时针方向移动degree°
turtle.left(degree) 逆时针方向移动degree°
turtle.pendown() 移动时绘制图形
turtle.penup() 提笔,不绘制图形移动
turtle.goto(x,y) 将画笔坐标移动到(x,y)位置
turtle.circle() 画圆,半径为正(负),表示画笔在左(右)
setx 将x轴移动到指定位置
sety 将y轴移动到指定位置
setheading(angle) 设置当前朝向为angle角度
home() 设置当前笔为原点,朝向为东
dot® 绘制一个指定直径和颜色的原点

4. 画笔控制命令

命令 说明
turtle.fillcolor(colorstring) 绘制图形的填充颜色
turtle.color(color1,color2) 同时设置pencolor=color1,fillcolor=color2
turtie.filling() 返回当前是否还在填充状态
turtle.begin_fill 开始填充图形
turtle.end_fill 结束填充图形
turtle.hideturtle() 隐藏画笔形状
turtle.showturtle() 显示画笔形状

5. 全局控制命令

命令 说明
turtle.clear() 清空turtle窗口,但turtle的位置和状态不会变
turtle.reset() 清空窗口重置turtle状态为起始状态
turtle.undo() 撤销上一个turtle动作
turtle.isvisable() 返回当前turtle是否可见
stamp() 复制当前图形
turtle.write(s [,font=(“font_name”,font_size,“font_type”)]) 写文本,s为文本内容,font是字体的参数,分别为字体名称,大小和类型;font为可选项,font参数也是可选项

6. 其他命令

命令 说明
turtle.mainloop()或turtle.done() 启动事件循环,使画布留在桌面
turtle.mode(mode=None) 设置乌龟模式(standard,logo,world)
turtle.delay(delay=None) 设置以毫秒为单位的延迟
turtle.begin_poly() 开始记录多边形的顶点,当前为第一个
turtle.end_poly() 结束记录多边形的顶点,当前为最后一个
turtle.get_poly() 返回多边形

7. 命令详解
turtle.circle(radius, extent=None, steps= None)
radius: 半径
extent: 弧度
steps: 内切正多边形的变数

# -*- codeing = utf-8 -*-
# @Time: 2020/9/18 21:53
# @Author: Xujie
# @File: social_man.py
# @Software: PyCharm
# -*- codeing = utf-8 -*-
# @Time: 2020/9/18 20:25
# @Author: Xujie
# @File: Python17-01.py
# @Software: PyCharm
import turtle
t = turtle.Pen()
def nose(x,y):
    t.penup()
    t.goto(x,y)
    t.pendown()
    t.setheading(-30)
    t.begin_fill()
    a = 0.4
    for i in range(120):
        if 0<=i<30 or 60<=i<90:
            a = a+0.08
            t.left(3)
            t.forward(a)
        else:
            a=a-0.08
            t.left(3)
            t.forward(a)
    t.end_fill()

    t.penup()
    t.setheading(90)
    t.forward(25)
    t.setheading(0)
    t.forward(10)
    t.pendown()
    t.color(255,155,192)
    t.setheading(10)
    t.begin_fill()
    t.circle(5)
    t.color(160,82,45)
    t.end_fill()

    t.penup()
    t.setheading(0)
    t.forward(20)
    t.setheading(0)
    t.forward(10)
    t.pendown()
    t.color(255, 155, 192)
    t.setheading(10)
    t.begin_fill()
    t.circle(5)
    t.color(160, 82, 45)
    t.end_fill()

def head(x,y):
    t.color((255,155,192),'pink')
    t.penup()
    t.goto(x,y)
    t.setheading(0)
    t.pendown()
    t.begin_fill()
    t.setheading(180)
    t.circle(300,-30)
    t.circle(100,-60)
    t.circle(80,-100)
    t.circle(150,-20)
    t.circle(60,-95)
    t.setheading(161)
    t.circle(-300,15)
    t.penup()
    t.goto(-100,100)
    t.pendown()
    t.setheading(-30)
    a = 0.4
    for i in range(60):
        if 0 <= i < 30 or 60 <= i < 90:
            a = a + 0.08
            t.lt(3)
            t.fd(a)
        else:
            a = a -0.08
            t.lt(3)
            t.fd(a)
            t.end_fill()

def ears(x,y):
    t.color((255, 155, 192), 'pink')
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.begin_fill()
    t.setheading(100)
    t.circle(-50, 50)
    t.circle(-10, 120)
    t.circle(-50, 56)
    t.end_fill()
    t.penup()
    t.setheading(90)
    t.forward(-12)
    t.setheading(0)
    t.forward(30)
    t.pendown()
    t.begin_fill()
    t.setheading(100)
    t.circle(-50, 50)
    t.circle(-10, 120)
    t.circle(-50, 56)
    t.end_fill()

def eyes(x,y):
    t.color((255, 155, 192),'white')
    t.penup()
    t.setheading(90)
    t.forward(-20)
    t.setheading(0)
    t.forward(-95)
    t.pendown()
    t.begin_fill()
    t.circle(15)
    t.end_fill()

    t.color('black')
    t.penup()
    t.setheading(90)
    t.forward(12)
    t.setheading(0)
    t.forward(-3)
    t.pendown()
    t.begin_fill()
    t.circle(3)
    t.end_fill()

    t.color((255, 155, 192),'white')
    t.penup()
    t.setheading(90)
    t.forward(-25)
    t.setheading(0)
    t.forward(40)
    t.pendown()
    t.begin_fill()
    t.circle(15)
    t.end_fill()

    t.color('black')
    t.penup()
    t.setheading(90)
    t.forward(12)
    t.setheading(0)
    t.forward(-3)
    t.pendown()
    t.begin_fill()
    t.circle(3)
    t.end_fill()

def cheek(x,y):
    t.color((255, 155, 192))
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.setheading(0)
    t.begin_fill()
    t.circle(30)
    t.end_fill()

def mouth(x,y):
    t.color(239,69,19)
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.setheading(-80)
    t.circle(30,40)
    t.circle(40,80)

def body(x,y):
    t.color('red',(255, 69, 71))
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.begin_fill()
    t.setheading(-130)
    t.circle(100, 10)
    t.circle(300, 30)
    t.setheading(0)
    t.forward(230)
    t.setheading(90)
    t.circle(300, 30)
    t.circle(100, 3)
    t.color((255,155,92),(255,100,100))
    t.setheading(-135)
    t.circle(-80, 63)
    t.circle(-150, 24)
    t.end_fill()

def hand(x,y):
    t.color(255, 155,192)
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.setheading(-160)
    t.circle(300, 15)
    t.penup()
    t.setheading(90)
    t.forward(15)
    t.setheading(0)
    t.forward(0)
    t.pendown()
    t.setheading(-10)
    t.circle(-20, 90)

    t.penup()
    t.setheading(90)
    t.forward(30)
    t.setheading(0)
    t.forward(237)
    t.pendown()
    t.setheading(-20)
    t.circle(-300, 15)

    t.penup()
    t.setheading(90)
    t.forward(20)
    t.setheading(0)
    t.forward(0)
    t.pendown()
    t.setheading(-170)
    t.circle(20, 90)

def foot(x,y):
    t.pensize(10)
    t.color(240,128,128)
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.setheading(-90)
    t.forward(40)
    t.setheading(-180)
    t.color('black')
    t.pensize(15)
    t.fd(20)

    t.pensize(10)
    t.color(240, 128, 128)
    t.penup()
    t.setheading(90)
    t.forward(40)
    t.setheading(0)
    t.forward(90)
    t.pendown()
    t.setheading(-90)
    t.forward(40)
    t.setheading(-180)
    t.color('black')
    t.pensize(15)
    t.fd(20)

def tail(x,y):
    t.pensize(4)
    t.color(255,155,192)
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.setheading(0)
    t.circle(70,20)
    t.circle(10,330)
    t.circle(70,30)

def setting():
    t.pensize(4)
    t.hideturtle()
    turtle.colormode(255)
    t.color((255, 155, 192), 'pink')
    turtle.setup(840,500)
    t.speed(10)

def main():
    setting()
    nose(-100,100)
    head(-69,167)
    ears(0,160)
    eyes(0,140)
    mouth(-20,30)
    body(-32,-8)
    hand(-56,-45)
    foot(2,-177)
    tail(148,-155)
    turtle.done()

if __name__ == '__main__':
    main()

在这里插入图片描述


版权声明:本文为qxj2422640226原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qxj2422640226/article/details/108685440