学堂 学堂 学堂公众号手机端

用python实现画多种类型桃心效果的代码是什么

lewis 6年前 (2019-06-26) 阅读数 10 #技术
很多朋友都对“用python实现画多种类型桃心效果的代码是什么”的内容比较感兴趣,对此小编整理了相关的知识分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获,那么感兴趣的朋友就继续往下看吧!
 



python画桃心表白

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

运行结果:

一行Python代码画心型

1、画I组成的心型代码

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)]))

2、画Love组成的心型代码

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)]))

3、画You组成的心型代码

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)]))

4、画Raven组成的心型代码

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)]))

以上就是关于“用python实现画多种类型桃心效果的代码是什么”的介绍了,感谢各位的阅读,如果大家想要了解更多相关的内容,欢迎关注博信,小编每天都会为大家更新不同的知识。
版权声明

本文仅代表作者观点,不代表博信信息网立场。

热门