Python每日练习之Turtle绘图

import turtle
startx, starty = -350, 300
def locate(x,y):
    turtle.penup()
    turtle.goto(startx+x,starty-y)
    turtle.pendown()


def draw(angle, lenth):
    turtle.seth(angle)
    turtle.forward(lenth)

def curvemove():
    for i in range(25):
        turtle.right(8)
        turtle.forward(4)

def main():
    turtle.pensize(4)
    turtle.speed(6)
    turtle.pencolor("red")
    # turtle.endfill()

    # turtle.screensize(500, 500, "blue")
    # 王
    locate(10,90)  # 定位画笔位置
    draw(0,90)     # 0度 向右画
    locate(25,146)
    draw(0,40)
    locate(45,90)
    draw(270,110)
    locate(10,200)
    draw(0,90)

    #宽
    locate(155,35)
    draw(315,20)
    locate(116,70)
    draw(270,20)
    locate(116,70)
    draw(0,100)
    locate(218,70)
    draw(270,20)   #上面是宝盖头
    locate(132,103)
    draw(0,80)
    locate(156,84)
    draw(270,25)
    locate(186,84)
    draw(270,25)
    locate(147,128)
    draw(270,50)
    locate(147,128)
    draw(0,50)
    locate(197,128)
    draw(270,50)
    locate(173,160)
    draw(270,40)
    locate(173,200)
    draw(200,50)  # 撇
    locate(173,200)
    draw(340, 50)  # 捺
    locate(223,215)
    draw(90,20)

    # 郭
    locate(400,28)
    draw(315,20)
    locate(370,53)
    draw(0,80)
    locate(378,87)
    draw(270,34)
    locate(378,87)
    draw(0,48)
    locate(426, 87)
    draw(270, 34)
    locate(378,118)
    draw(0,48)
    ## 子
    locate(370,141)
    draw(0,55)
    locate(430,141)
    draw(225,30)
    locate(407,163)
    draw(270,40)
    locate(410,207)
    draw(180,30)
    locate(360,168)
    draw(0,100)
    ## 双儿刀转为3
    locate(460,60)
    draw(270,156)
    locate(460,60)
    draw(0,50)
    locate(510,60)
    draw(270,40)
    locate(510,100)
    draw(180,40)
    locate(470,100)
    draw(0,40)
    locate(510,100)
    draw(270,50)
    locate(510,150)
    draw(180,40)

    # 茜
    locate(532,60)
    draw(0, 110)
    locate(572,46)
    draw(270,40)
    locate(632,46)
    draw(270,40)
    ## 西
    locate(540,110)
    draw(0,110)
    locate(542,148)
    draw(270,60)
    locate(542,148)
    draw(0,100)
    locate(642,148)
    draw(270,60)
    locate(574,116)
    draw(270,60)
    locate(573,176)
    draw(180,15)
    locate(600,116)
    draw(270,60)
    locate(600,176)
    draw(0,18)
    locate(542,208)
    draw(0,100)

    #画爱心
    turtle.begin_fill()
    locate(290,177)
    turtle.left(140)
    turtle.forward(60)
    curvemove()
    turtle.left(120)
    curvemove()
    turtle.forward(60)

    turtle.done()

if __name__ == "__main__":
    main()

最后动态输出:
Python每日练习之Turtle绘图_第1张图片

你可能感兴趣的:(Pyhton从新手到大师,python)