Python制作七夕表白案例分享
一、記錄一起走過的那些日子
講述和親愛的TA一起經(jīng)歷的那些故事
- 那些初見印象
- 那些浪漫的開始
- 那些銘記于心的大小事
- 那些經(jīng)歷的曲折
- 那些經(jīng)歷的幸福與快樂
- 那些珍貴的瞬間
- 那些對未來的期許/計劃
二、創(chuàng)意代碼表白
以程序員的方式撒狗糧,專業(yè)浪漫,值得擁有!
2.1、效果演示
1、顯示表白文字
2、顯示人物和愛心
2.2、制作步過程
主要是編寫如下的幾個函數(shù),來實現(xiàn)七夕表白的功能。
2.2.1、清屏函數(shù)
# 清屏函數(shù) def clear_all(): turtle.penup() turtle.goto(0, 0) turtle.color('white') turtle.pensize(800) turtle.pendown() turtle.setheading(0) turtle.fd(300) turtle.bk(600)
2.2.2、重定位海龜?shù)奈恢?/h4>
# 重定位海龜?shù)奈恢?
def go_to(x, y, state):
turtle.pendown() if state else turtle.penup()
turtle.goto(x, y)
# 重定位海龜?shù)奈恢? def go_to(x, y, state): turtle.pendown() if state else turtle.penup() turtle.goto(x, y)
2.2.3、顯示文字
# 第一個畫面,顯示文字 def paintingOne(): turtle.penup() turtle.goto(-300, 0) turtle.color('pink') turtle.write('時光讓我們相遇,我的情人,七夕快樂?。。?, font=('楷體', 24, 'normal')) time.sleep(3)
2.2.4、畫出人物
# 畫出人物 def draw_people(x, y): turtle.penup() turtle.goto(x, y) turtle.pendown() turtle.pensize(2) turtle.color('pink') turtle.setheading(0) turtle.circle(60, 360) turtle.penup() turtle.setheading(90) turtle.fd(75) turtle.setheading(180) turtle.fd(20) turtle.pensize(4) turtle.pendown() turtle.circle(2, 360) turtle.setheading(0) turtle.penup() turtle.fd(40) turtle.pensize(4) turtle.pendown() turtle.circle(-2, 360) turtle.penup() turtle.goto(x, y) turtle.setheading(-90) turtle.pendown() turtle.fd(20) turtle.setheading(0) turtle.fd(35) turtle.setheading(60) turtle.fd(10) turtle.penup() turtle.goto(x, y) turtle.setheading(-90) turtle.pendown() turtle.fd(40) turtle.setheading(0) turtle.fd(35) turtle.setheading(-60) turtle.fd(10) turtle.penup() turtle.goto(x, y) turtle.setheading(-90) turtle.pendown() turtle.fd(60) turtle.setheading(-135) turtle.fd(60) turtle.bk(60) turtle.setheading(-45) turtle.fd(30) turtle.setheading(-135) turtle.fd(35) turtle.penup()
2.2.5、畫愛心
# 畫愛心 def draw_heart(size): turtle.color('red', 'pink') turtle.pensize(2) turtle.pendown() turtle.setheading(150) turtle.begin_fill() turtle.fd(size) turtle.circle(size * -3.745, 45) turtle.circle(size * -1.431, 165) turtle.left(120) turtle.circle(size * -1.431, 165) turtle.circle(size * -3.745, 45) turtle.fd(size) turtle.end_fill()
2.2.6、主函數(shù)
def Main(): turtle.setup(900, 500) paintingOne() clear_all() paintingTwo() clear_all() turtle.done()
2.2.7、調(diào)用主函數(shù)
if __name__ == '__main__': Main()
2.3、代碼文件
import turtle import time # 清屏函數(shù) def clear_all(): turtle.penup() turtle.goto(0, 0) turtle.color('white') turtle.pensize(800) turtle.pendown() turtle.setheading(0) turtle.fd(300) turtle.bk(600) # 重定位海龜?shù)奈恢? def go_to(x, y, state): turtle.pendown() if state else turtle.penup() turtle.goto(x, y) # 畫愛心 def draw_heart(size): turtle.color('red', 'pink') turtle.pensize(2) turtle.pendown() turtle.setheading(150) turtle.begin_fill() turtle.fd(size) turtle.circle(size * -3.745, 45) turtle.circle(size * -1.431, 165) turtle.left(120) turtle.circle(size * -1.431, 165) turtle.circle(size * -3.745, 45) turtle.fd(size) turtle.end_fill() # 第一個畫面,顯示文字 def paintingOne(): turtle.penup() turtle.goto(-300, 0) turtle.color('pink') turtle.write('時光讓我們相遇,我的情人,七夕快樂?。。?, font=('楷體', 24, 'normal')) time.sleep(3) # 畫出人物 def draw_people(x, y): turtle.penup() turtle.goto(x, y) turtle.pendown() turtle.pensize(2) turtle.color('pink') turtle.setheading(0) turtle.circle(60, 360) turtle.penup() turtle.setheading(90) turtle.fd(75) turtle.setheading(180) turtle.fd(20) turtle.pensize(4) turtle.pendown() turtle.circle(2, 360) turtle.setheading(0) turtle.penup() turtle.fd(40) turtle.pensize(4) turtle.pendown() turtle.circle(-2, 360) turtle.penup() turtle.goto(x, y) turtle.setheading(-90) turtle.pendown() turtle.fd(20) turtle.setheading(0) turtle.fd(35) turtle.setheading(60) turtle.fd(10) turtle.penup() turtle.goto(x, y) turtle.setheading(-90) turtle.pendown() turtle.fd(40) turtle.setheading(0) turtle.fd(35) turtle.setheading(-60) turtle.fd(10) turtle.penup() turtle.goto(x, y) turtle.setheading(-90) turtle.pendown() turtle.fd(60) turtle.setheading(-135) turtle.fd(60) turtle.bk(60) turtle.setheading(-45) turtle.fd(30) turtle.setheading(-135) turtle.fd(35) turtle.penup() # 第二個畫面,顯示發(fā)射愛心的小人 def paintingTwo(): turtle.speed(10) draw_people(-250, 20) turtle.penup() turtle.goto(-150, -30) draw_heart(14) turtle.penup() turtle.goto(-20, -60) draw_heart(25) turtle.penup() turtle.goto(250, -100) draw_heart(45) turtle.hideturtle() time.sleep(1) def Main(): turtle.setup(900, 500) paintingOne() clear_all() paintingTwo() clear_all() turtle.done() if __name__ == '__main__': Main()
到此這篇關(guān)于Python制作七夕表白案例分享的文章就介紹到這了,更多相關(guān)Python制作七夕表白實例內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
OpenCV-Python 實現(xiàn)兩張圖片自動拼接成全景圖
圖片的全景拼接如今已不再稀奇,現(xiàn)在的智能攝像機和手機攝像頭基本都帶有圖片自動全景拼接的功能,本文使用OpenCV-Python 實現(xiàn)兩張圖片自動拼接成全景圖,感興趣的可以了解一下2021-06-06python使用OpenCV獲取高動態(tài)范圍成像HDR
這篇文章主要介紹了python使用OpenCV獲取高動態(tài)范圍成像HDR,如何使用不同曝光設(shè)置拍攝的多張圖像創(chuàng)建高動態(tài)范圍圖像HDR,下文嗎更詳細(xì)的內(nèi)容介紹,需要的小伙伴可以參考一下2022-04-04python+requests接口自動化框架的實現(xiàn)
這篇文章主要介紹了python+requests接口自動化框架的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08python實現(xiàn)將元祖轉(zhuǎn)換成數(shù)組的方法
這篇文章主要介紹了python實現(xiàn)將元祖轉(zhuǎn)換成數(shù)組的方法,涉及Python中l(wèi)ist方法的使用技巧,需要的朋友可以參考下2015-05-05pycharm通過ssh遠(yuǎn)程連接服務(wù)器并運行代碼詳細(xì)圖文
在運行項目的過程中,由于自己電腦GPU不夠,通常需要將項目放到服務(wù)器上運行,這時就會遇到如何將pycharm和服務(wù)器進行連接,下面這篇文章主要給大家介紹了關(guān)于pycharm通過ssh遠(yuǎn)程連接服務(wù)器并運行代碼的相關(guān)資料,需要的朋友可以參考下2024-03-03