用python绘制心形_python小趣味_520绘制一个心形.
#!/usr/bin/env python#coding:utf-8
importturtleimporttime#畫愛心的頂部
defLittleHeart():for i in range(200):
turtle.right(1)
turtle.forward(2)#輸入表白的語句,默認I Love you
love = input('Please enter a sentence of love, otherwise the default is "I Love you":')#輸入署名或者贈誰,沒有不執行
me = input('Please enter pen name, otherwise the default do not execute:')if love == '':
love= 'I Love you'
#窗口大小
turtle.setup(width=900, height=500)#顏色
turtle.color('red', 'pink')#筆粗細
turtle.pensize(3)#速度
turtle.speed(1)#提筆
turtle.up()#隱藏筆
turtle.hideturtle()#去到的坐標,窗口中心為0,0
turtle.goto(0, -180)
turtle.showturtle()#畫上線
turtle.down()
turtle.speed(1)
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', 'pink')#在心中寫字 font可以設置字體自己電腦有的都可以設 align開始寫字的位置
turtle.write(love, font=('gungsuh', 30,), align="center")
turtle.up()
turtle.hideturtle()
time.sleep(2)#在心中寫字 二次
turtle.goto(0, 0)
turtle.showturtle()
turtle.color('red', 'pink')
turtle.write(love, font=('gungsuh', 30,), align="center")
turtle.up()
turtle.hideturtle()#寫署名
if me != '':
turtle.color('black', 'pink')
time.sleep(2)
turtle.goto(180, -180)
turtle.showturtle()
turtle.write(me, font=(20,), align="center", move=True)#點擊窗口關閉
window =turtle.Screen()
window.exitonclick()
總結
以上是生活随笔為你收集整理的用python绘制心形_python小趣味_520绘制一个心形.的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微机原理换行代码_微机原理课程设计——汇
- 下一篇: python3.6库参考手册_pytho