5月20号到啦!想送给对方自己亲手做的礼物,那这个520爱心就挺不错的。

源代码:

import turtle as t
import time
import pygame
def hart_arc():
    t.hideturtle()  # 隐藏画笔
    for i in range(200):
        t.right(1)
        t.forward(2)
t.hideturtle()
t.Screen().bgcolor("#d3dae8")
t.setup(1100,800)
#插入音乐,更有感觉
#音乐路径需要自己添加
file=r'D:\KuGou\新建文件夹\陈柯宇 - 直到遇见了你我只喜欢你 (Live片段).mp3'# 音乐的路径
pygame.mixer.init()# 初始化
track = pygame.mixer.music.load(file)# 加载音乐文件
pygame.mixer.music.play(start=0.0)
t.color('pink') # 画笔颜色,可以自己选择
t.pensize(5)
t.penup()
t.goto(-100,-131)
#这个位置是我根据我画的数字520大致计算出的位置,如果需要的话,可以自己调整初始位置哦
t.pendown()
t.left(140) # 向左旋转140度
t.begin_fill() # 标记背景填充位置
# 画心形直线( 左下方 )
t.forward(224) # 向前移动画笔,长度为224
# 画爱心圆弧
hart_arc() # 左侧圆弧
t.left(120) # 调整画笔角度
hart_arc() # 右侧圆弧
# 画心形直线( 右下方 )
t.forward(224)
t.penup()
t.goto(-200,150)
t.pendown()
t.color("pink")
#数字520
#5
t.goto(-270,150)
t.right(90)
t.goto(-270,80)
t.right(90)
t.goto(-200,80)
t.left(90)
t.goto(-200,10)
t.left(90)
t.goto(-270,10)
#2
t.penup()
t.goto(-160,150)
t.pendown()
t.goto(-90,150)
t.right(90)
t.goto(-90,80)
t.left(90)
t.goto(-160,80)
t.right(90)
t.goto(-160,10)
t.left(90)
t.goto(-90,10)
#0
t.penup()
t.goto(-50,150)
t.pendown()
t.goto(30,150)
t.left(90)
t.goto(30,10)
t.left(90)
t.goto(-50,10)
t.left(90)
t.goto(-50,150)
t.done()

 

在python中没有直接画圆弧的函数,所以我将很小的一段弧看作是直线,循环执行,就能得到圆弧啦。

import turtle as t
t.setup(width=1100, height=800) # 窗口(画布)大小
t.hideturtle()  # 隐藏画笔
t.penup()
t.goto(120,120)
t.pendown()
for i in range(360):
    t.right(1)
    t.forward(3)
for i in range(360):
    t.right(1)
    t.forward(2)
for i in range(360):
    t.right(1)
    t.forward(1)
t.done()

我画了三个不同的圆,可以看看区别

19bf14c91b0e4f88aafcc3106745e12f.png

 

附上运行截图

aa6e3df7cfe44bc2a7abe98c99fcf2eb.png

 

 

 

 

 

 

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐