python代码示例表白-表白 - python代码库 - 云代码

这篇博客展示了如何使用Python的turtle模块绘制出一个由大圆、小圆和直线构成的心形图案,以及一个指向心形的箭头。通过定义不同函数实现细节绘制,包括大圆、小圆和直线的绘制。最后还添加了箭头的头部,并在底部写上了作者名字。
摘要由CSDN通过智能技术生成

[python]代码库from turtle import *

from time import sleep

def go_to(x, y):

up()

goto(x, y)

down()

def big_Circle(size): #函数用于绘制心的大圆

speed(1)

for i in range(150):

forward(size)

right(0.3)

def small_Circle(size): #函数用于绘制心的小圆

speed(1)

for i in range(210):

forward(size)

right(0.786)

def line(size):

speed(1)

forward(51*size)

def heart( x, y, size):

go_to(x, y)

left(150)

begin_fill()

line(size)

big_Circle(size)

small_Circle(size)

left(120)

small_Circle(size)

big_Circle(size)

line(size)

end_fill()

def arrow():

pensize(10)

setheading(0)

go_to(-400, 0)

left(15)

forward(150)

go_to(339, 178)

forward(150)

def arrowHead():

pensize(1)

speed(1)

color('red', 'red')

begin_fill()

left(120)

forward(20)

right(150)

forward(35)

right(120)

forward(35)

right(150)

forward(20)

end_fill()

def main():

pensize(2)

color('red', 'pink')

#getscreen().tracer(30, 0) #取消注释后,快速显示图案

heart(200, 0, 1) #画出第一颗心,前面两个参数控制心的位置,函数最后一个参数可控制心的大小

setheading(0) #使画笔的方向朝向x轴正方向

heart(-80, -100, 1.5) #画出第二颗心

arrow() #画出穿过两颗心的直线

arrowHead() #画出箭的箭头

go_to(400, -300)

write("author:520Python", move=True, align="left", font=("宋体", 30, "normal"))

done()

main()

201903221632.jpg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值