程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python do make the Tanabata instance project - let your lovers heart

編輯:Python

文章目錄

  • PythonDo make the Tanabata instance project-Let your lover's heart
  • 前言
  • 一、記錄一起走過的那些日子
  • 二、創意代碼表白
    • 2.1、效果演示
    • 2.2、Process step
      • 2.2.1、清屏函數
      • 2.2.2、重定位海龜的位置
      • 2.2.3、顯示文字
      • 2.2.4、Draw the character
      • 2.2.5、畫愛心
      • 2.2.6、主函數
      • 2.2.7、調用主函數
    • 2.3、代碼文件
  • 三、Do a little short

PythonDo make the Tanabata instance project-Let your lover's heart

前言

七夕來襲!是時候展現專屬於程序員的浪漫了!你打算怎麼給心愛的人表達愛意?鮮花禮物?代碼表白?還是創意DIY?In this paper, with aPythonExamples of projects to do lover as a gift.

一、記錄一起走過的那些日子

講述和親愛的TA一起經歷的那些故事

  • 那些初見印象
  • 那些浪漫的開始
  • 那些銘記於心的大小事
  • 那些經歷的曲折
  • 那些經歷的幸福與快樂
  • 那些珍貴的瞬間
  • 那些對未來的期許/計劃

二、創意代碼表白

以程序員的方式撒狗糧,專業浪漫,值得擁有!

2.1、效果演示

1、Do show words

2、According to character and love

2.2、Process step

Mainly is to write the following several functions,To implement the function of the Chinese expression.

2.2.1、清屏函數


# 清屏函數
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、重定位海龜的位置

# 重定位海龜的位置
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('Time let us meet together,我的情人,七夕快樂!!!', font=('楷體', 24, 'normal'))
time.sleep(3)

2.2.4、Draw the character

# Draw the character
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、主函數

def Main():
turtle.setup(900, 500)
paintingOne()
clear_all()
paintingTwo()
clear_all()
turtle.done()

2.2.7、調用主函數

if __name__ == '__main__':
Main()

2.3、代碼文件


import turtle
import time
# 清屏函數
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)
# 重定位海龜的位置
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('Time let us meet together,我的情人,七夕快樂!!!', font=('楷體', 24, 'normal'))
time.sleep(3)
# Draw the character
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()
# 第二個畫面,顯示發射愛心的小人
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()

三、Do a little short

遇見即是上上簽.

遇到了你,Just feel the world more bright.

浮生若夢,慕爾如星.

Meet only at first sight of see,Surprised to get long in the future.

Those who used to wait,Think love is slowly loading.直到遇見你,Just know that love is the acceleration.

在遇見你之前,I never thought I was total site day south.

千山萬水就當是伏筆,總會遇到姗姗來遲的你.

Want to take you up,Want to and you elope to the moon,But also thanks to gravity,讓我遇見你.

I have to waste time to death,Because met you just understand have a nice.

白茶清歡無別事,我在等風,也在等你.

Very clear and bright white pony,At the hollow.Raw silage a bunch of,The man is jade.No Jin Yuer sound,Distant heart.


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved