Python画心

#需要再控制台按住turtule包 python2的安装命令
pip install turtule
#Python3 的安装命令
pip3 install turtle

 

import turtle as t


def face(x, y):  # 脸

    t.setheading(-90)

    t.penup()

    t.goto(x, y)

    t.pendown()

    t.backward(15)  # 左脸

    t.circle(70, -80)

    t.setheading(80)  # 左耳

    t.circle(-150, 15)

    t.circle(-15, 180)

    t.setheading(-115)

    t.circle(-150, 13)

    t.setheading(10)

    t.circle(-100, 10)

    t.setheading(70)  # 右耳

    t.circle(-150, 20)

    t.circle(-15, 180)

    t.circle(-150, 16)

    t.setheading(10)

    t.setheading(160)  # 右脸

    t.circle(60, -130)

    t.setheading(-75)

    t.forward(40)


def word(x, y):  # “如何骗人”

    t.pensize(2)

    t.pencolor("black")

    t.setheading(0)

    t.penup()

    t.goto(x, y)

    t.pendown()

    t.forward(10)  # “如”

    t.penup()

    t.setheading(90)

    t.forward(8)

    t.pendown()

    t.setheading(-120)

    t.forward(15)

    t.setheading(-45)

    t.forward(12)

    t.penup()

    t.setheading(80)

    t.forward(15)

    t.pendown()

    t.setheading(-125)

    t.forward(16)

    t.penup()

    t.setheading(42)

    t.forward(16)

    t.pendown()

    t.setheading(-90)

    t.forward(10)

    t.penup()

    t.backward(11)

    t.pendown()

    t.setheading(0)

    t.forward(8)

    t.setheading(-90)

    t.forward(10)

    t.penup()

    t.setheading(180)

    t.forward(8)

    t.pendown()

    t.setheading(0)

    t.forward(8)

    t.penup()  # “何”

    t.goto(x + 7, y - 18)

    t.pendown()

    t.setheading(-135)

    t.forward(13)

    t.penup()

    t.goto(x + 5, y - 20)

    t.pendown()

    t.setheading(-90)

    t.forward(16)

    t.penup()

    t.goto(x + 11, y - 18)

    t.pendown()

    t.setheading(0)

    t.forward(13)

    t.penup()

    t.goto(x + 12, y - 22)

    t.pendown()

    t.setheading(-90)

    t.forward(8)

    t.penup()

    t.goto(x + 12, y - 22)

    t.pendown()

    t.setheading(0)

    t.forward(6)

    t.setheading(-90)

    t.forward(8)

    t.penup()

    t.goto(x + 11, y - 31)

    t.pendown()

    t.setheading(0)

    t.forward(6)

    t.penup()

    t.goto(x + 21, y - 19)

    t.pendown()

    t.setheading(-90)

    t.forward(18)

    t.setheading(145)

    t.forward(5)

    t.penup()  # “骗”

    t.goto(x + 40, y + 3)

    t.pendown()

    t.setheading(0)

    t.forward(10)

    t.setheading(-90)

    t.forward(7)

    t.penup()

    t.goto(x + 45, y + 3)

    t.pendown()

    t.setheading(-90)

    t.forward(10)

    t.setheading(0)

    t.forward(7)

    t.setheading(-100)

    t.forward(10)

    t.setheading(145)

    t.forward(4)

    t.penup()

    t.goto(x + 38, y - 12)

    t.pendown()

    t.setheading(0)

    t.forward(11)

    t.penup()

    t.goto(x + 57, y + 9)

    t.pendown()

    t.setheading(-45)

    t.forward(4)

    t.penup()

    t.goto(x + 54, y + 3)

    t.pendown()

    t.setheading(0)

    t.forward(13)

    t.setheading(-90)

    t.forward(5)

    t.setheading(180)

    t.forward(12)

    t.penup()

    t.goto(x + 54, y + 3)

    t.pendown()

    t.setheading(90)

    t.circle(90, -10)

    t.penup()

    t.goto(x + 56, y - 5)

    t.pendown()

    t.setheading(-90)

    t.forward(11)

    t.penup()

    t.goto(x + 56, y - 5)

    t.pendown()

    t.setheading(0)

    t.forward(13)

    t.setheading(-90)

    t.forward(12)

    t.setheading(145)

    t.forward(4)

    t.penup()

    t.goto(x + 56, y - 10)

    t.pendown()

    t.setheading(0)

    t.forward(13)

    t.penup()

    t.goto(x + 56, y - 10)

    t.pendown()

    t.setheading(0)

    t.forward(13)

    t.penup()

    t.goto(x + 60, y - 4)

    t.pendown()

    t.setheading(-90)

    t.forward(10)

    t.penup()

    t.goto(x + 64, y - 4)

    t.pendown()

    t.setheading(-90)

    t.forward(10)

    t.penup()  # “人”

    t.goto(x + 60, y - 19)

    t.pendown()

    t.setheading(70)

    t.circle(50, -30)

    t.penup()

    t.goto(x + 56, y - 27)

    t.pendown()

    t.setheading(130)

    t.circle(-50, -20)


def book(x, y):  # 书

    t.setheading(-90)

    t.penup()

    t.goto(x, y)

    t.fillcolor("red")

    t.begin_fill()

    t.pendown()

    t.forward(60)

    t.setheading(0)

    t.circle(-100, 25)

    t.setheading(90)

    t.forward(59)

    t.setheading(-25)

    t.circle(-100, -25)

    t.penup()

    t.setheading(-14)

    t.forward(46)

    t.pendown()

    t.setheading(15)

    t.circle(-100, 25)

    t.setheading(-90)

    t.forward(58)

    t.setheading(-11)

    t.circle(-105, -25)

    t.end_fill()


def eyes(x, y):  # 五官

    t.setheading(-20)

    t.penup()

    t.goto(x, y)

    t.pendown()

    t.forward(10)

    t.setheading(0)

    t.penup()

    t.forward(10)

    t.pendown()

    t.setheading(20)

    t.forward(10)

    t.setheading(-160)

    t.penup()

    t.forward(50)

    t.pendown()

    t.setheading(0)

    t.forward(15)

    t.penup()

    t.forward(25)

    t.pendown()

    t.forward(18)

    t.setheading(-145)

    t.penup()

    t.forward(45)

    t.pendown()

    t.setheading(0)

    t.forward(10)


def cheek(x, y):  # 腮红

    t.setheading(0)

    for i in range(1, 4):
        t.color("pink")

        t.pensize(4)

        t.penup()

        t.right(110)

        t.goto(x, y)

        t.pendown()

        t.forward(9)

        t.left(110)

        x += 9

    t.pencolor("black")


def hands(x, y):  # 小手手

    t.penup()

    t.goto(x, y)

    t.pendown()

    t.fillcolor("white")

    t.begin_fill()

    t.circle(10)

    t.end_fill()

    t.penup()

    t.setheading(5)

    t.forward(120)

    t.pendown()

    t.fillcolor("white")

    t.begin_fill()

    t.setheading(-165)

    t.forward(35)

    t.circle(10, 180)

    t.forward(15)

    t.end_fill()


def heart(x, y, z):  # 爱心

    t.setheading(110)

    t.pensize(2)

    t.pencolor("black")

    t.penup()

    t.goto(x, y)

    t.pendown()

    t.fillcolor("red")

    t.begin_fill()  # 左半边

    t.circle(50, 180)

    t.circle(180, 37)

    t.left(46)  # 右半边

    t.circle(180, 37)

    t.circle(50, 182)

    t.end_fill()


def main():
    """
        主函数
    """

    t.pensize(0)

    t.speed(6)

    face(-95, 55)

    eyes(-45, 110)

    cheek(-80, 80)

    cheek(0, 80)

    book(-110, 55)

    hands(-110, 5)

    word(-100, 35)

    heart(150, 0, 1)

    t.hideturtle()

    t.exitonclick()


if __name__ == "__main__":
    main()

展示效果:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值