用python实现画多种类型桃心效果的代码是什么
Admin 2022-09-09 群英技术资讯 476 次浏览
python用turtle画简单图案比较方便,大一学python的turtle模块时,记得要画各种图案,如国旗,桃心等等图案,期末课程设计时有可能还会遇到画54张扑克牌,当初室友就被迫选了这道题。
有时候程序猿遇到自己悄悄喜欢的女生又不敢表白,那么就用turtle来实现表白吧!!!!!!!
import turtle import time def LittleHeart(): for i in range(200): turtle.right(1) turtle.forward(2) isLove=input('你会一直爱她吗?(Y or N)\n') run =1 while(run): if isLove=="Y": me="" love="" if love=='': love=' 草莓 I love you' turtle.setup(width=900, height=500) turtle.color('red','red') turtle.pensize(3) turtle.speed(50) turtle.up() turtle.hideturtle() turtle.goto(0,-180) turtle.showturtle() turtle.down() turtle.speed(5) turtle.begin_fill() turtle.left(140) turtle.forward(224) LittleHeart() turtle.left(120) LittleHeart() turtle.forward(224) turtle.end_fill() turtle.pensize(5) turtle.up() turtle.hideturtle() turtle.goto(0,0) turtle.showturtle() turtle.color('#CD5C5C','blue') turtle.write(love,font=('gungsuh',30,),align="center") turtle.up() turtle.hideturtle() if me !='': turtle.color('yellow', 'red') time.sleep(2) turtle.goto(180,-180) turtle.showturtle() turtle.write(me, font=(20,), align="center", move=True) window=turtle.Screen() window.exitonclick() run =0 else: print("活该单身一辈子") print("!!!!!!!!!再给你一次机会!!!!!!!!") isLove=input('你会一直爱她吗?(Y or N)\n') continue
运行结果:
print('\n'.join([''.join([('I'[(x-y) % len('I')]if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 <= 0 else ' ')for x in range(-30, 30)])for y in range(30, -30, -1)]))
print('\n'.join([''.join([('Love'[(x-y) % len('Love')]if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 <= 0 else ' ')for x in range(-30, 30)])for y in range(30, -30, -1)]))
print('\n'.join([''.join([('You'[(x-y) % len('You')]if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 <= 0 else ' ')for x in range(-30, 30)])for y in range(30, -30, -1)]))
print('\n'.join([''.join([('Raven'[(x-y) % len('Raven')]if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 <= 0 else ' ')for x in range(-30, 30)])for y in range(30, -30, -1)]))
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要为大家介绍了python闭包和装饰器,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能够给你带来帮助
Python语言处理字符串、数组类的问题时有一定概率需要使用切片方法,本文主要介绍了Python 切片索引越界的问题,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要为大家详细介绍了Python和C语言如何利用栈的数据结构分别实现将十进制数转换成二进制数,文中的示例代码讲解详细,需要的可以参考一下
“回调函数就是一个通过函数指针调用的函数。如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用来调用其所指向的函数时
Matplotlib是Python的绘图库,它能让使用者很轻松地将数据图形化,并且提供多样化的输出格式。本文将为大家介绍如何用matplotlib绘制饼图和堆叠图,感兴趣的朋友可以学习一下
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008