turtle 情人节给女友画个心

turtle 情人节给女友画个心_第1张图片
代码

from random import random
from turtle import*
while(True):
    pencolor("black")
    fillcolor("cyan")
    setup(800,800)
    speed(5)
    pensize(2)
    begin_fill()
    left(90)
    circle(120,180)
    circle(360,70)
    left(38)
    circle(360,70)
    circle(120,180)
    end_fill()
    color("blue")
    penup()
    goto(-50, -120)
    pendown()
    write("子辰", font=("Times", 38, "bold"))

    # 隐藏箭头
    hideturtle()
    # 暂停界面,使得用户能够看见展示的图形
    def randomcolor():
        color = (random(), random(), random())
        return color


    def pink():
        color = (0, random(), 1)
        return color


    def randomrange(min, max):
        return min + (max - min) * random()


    def moveto(x, y):
        penup()
        goto(x, y)
        pendown()


    def heart(r, a):
        factor = 180
        seth(a)
        circle(-r, factor)
        fd(2 * r)
        right(90)
        fd(2 * r)
        circle(-r, factor)


    # set canvas dimension
    setup(800, 800)
    speed(20)

    pensize(2)
    pencolor(randomcolor())
    fillcolor(randomcolor())

    penup()
    for i in range(20):
        goto(randomrange(-300, 300), randomrange(-300, 300))
        begin_fill()
        fillcolor(pink())
        heart(randomrange(10, 30), randomrange(0, 20))
        end_fill()

    moveto(400, -400)

    done()

你可能感兴趣的:(编程的浪漫)