当前位置:网站首页>Haven't expressed the artifact yet? Valentine's Day is coming. Please send her a special gift~
Haven't expressed the artifact yet? Valentine's Day is coming. Please send her a special gift~
2022-07-03 20:26:00 【It's dream】
Hello, Hello, my name is Dream ah , An interesting Python Blogger , Please go easy on me
2021 Blog star of the year TOP100,2021 Blog star of the year TOP5,Python Quality creators in the field , Welcome to cooperate with me ( At the end of the article VX Want to join the learning exchange group or Learning materials welcome +++)Introductory notes : This paradise never lacks genius , Hard work is your final ticket !
Last , May we all shine where we can't see , Let's make progress together
“ Ten thousand times sad , There will still be Dream, I've been waiting for you in the warmest place ”, It's me ! Ha ha ha ~
Preface :
A blink of an eye , Another Valentine's day , Are you still alone this year ?
if No :
Bless you , keep looking down to the bottom , After reading, the feelings are firm
print(' Successfully enter the good man level ')
elif yes :
Hug iron , keep looking down to the bottom , After reading the slip
print(' Successfully enter the sea king level ')
One 、 Background story
On the eve of Valentine's day , There are also many private letters from friends Dream, Can you help me take it off and place an order , Issue a confession artifact ! Many friends used this last year : python Cross year declaration artifact – You deserve it !, This year, he successfully joined the sea king , Thank you in succession Dream, Ask me if there is anything else good . A senior old sea king's autobiography ( No ): There are good things ! There are still a lot of it !
So I took the risk of not spending Valentine's day with my girlfriend ,Dream The latest confession artifact was made overnight . It's coming to meet the needs of our friends : Valentine's day exclusive gift , Give it to her who you love most ~ If you don't talk much, see the effect first :
Hey, hey, hey , Is it very nice ah ! Don't worry when you see this , For my Valentine's day , Do you have to give me one button three times first !!!
Now let's talk slowly , Please take a seat in the front row , Take your own popcorn ( give the thumbs-up + A collection is equivalent to a popcorn )
Two 、 The production process
1. Interactive interface
Here we use the definition clear_screen() Function to clear the screen for each animation , Conducive to the next animation display . The overall situation applies turtle library 、time Time bank 、random Random library , as well as tkinter Kuhe threading library .
Installation method :cmd And then directly pip install turtle( The name of the required Library )
# Realization of clean screen
def clear_screen():
turtle.penup() # Brush up
turtle.goto(0,0) # Locate the (0,0)
turtle.color('white')
turtle.pensize(800) # Brush thickness
turtle.pendown() # The paintbrush falls
turtle.setheading(0) # Set orientation
turtle.fd(300) # Forward
turtle.bk(600) # back off
# Initialize the turtle's position
def go_start(x, y, state):
turtle.pendown() if state else turtle.penup()
turtle.goto(x, y)
# Draw line ,state When true, the turtle returns to the origin , When it's false, it doesn't go back to the original starting point
def draw_line(length, angle, state):
turtle.pensize(1)
turtle.pendown()
turtle.setheading(angle)
turtle.fd(length)
turtle.bk(length) if state else turtle.penup()
turtle.penup()
2. Draw a little man who emits love
Here are some operations of turtle drawing :
# Draw a picture of a little man who radiates love
def draw_people(x, y):
turtle.speed(0)
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.pensize(2)
turtle.color('black')
turtle.setheading(0)
turtle.circle(35, 360)
turtle.penup()
turtle.pensize(3)
turtle.setheading(90)
turtle.fd(45)
turtle.setheading(180)
turtle.fd(20)
turtle.setheading(0)
turtle.fd(35)
turtle.pendown()
turtle.circle(4, 360)
turtle.penup()
turtle.goto(x, y)
turtle.pensize(2)
turtle.setheading(0)
turtle.fd(20)
turtle.setheading(90)
turtle.fd(20)
turtle.setheading(-90)
turtle.pendown()
turtle.circle(5, 180)
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()
3. Draw an arrow through the heart
The text in this can be modified according to your own needs , You can change it according to your own needs !
# Draw love
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()
turtle.speed(0)
# Draw arrow feathers
def draw_feather(size):
angle = 30 # The angle of the arrow
feather_num = size // 6 # The number of feathers
feather_length = size // 3 # The length of the feather
feather_gap = size // 10 # The spacing of feathers
for i in range(feather_num):
draw_line(feather_gap, angle + 180, False) # Arrow handle , No
draw_line(feather_length, angle + 145, True) # wing , To turn back
draw_line(feather_length, angle + 145, False)
draw_line(feather_num * feather_gap, angle, False)
draw_line(feather_length, angle + 145 + 180, False)
for i in range(feather_num):
draw_line(feather_gap, angle + 180, False) # Arrow handle , No
draw_line(feather_length, angle - 145, True) # wing , To turn back
draw_line(feather_length, angle - 145, False)
draw_line(feather_num * feather_gap, angle, False)
draw_line(feather_length, angle - 145 + 180, False)
# Draw an arrow through the heart , At last the head of the arrow was not drawn , Use turtles instead of
def arrow_heart(x, y, size):
go_start(x, y, False)
draw_heart(size * 1.15)
turtle.setheading(-150)
turtle.penup()
turtle.fd(size * 2.2)
draw_heart(size)
turtle.penup()
turtle.setheading(150)
turtle.fd(size * 2.2)
turtle.color('black')
draw_feather(size)
turtle.pensize(4)
turtle.setheading(30)
turtle.pendown()
turtle.fd(size * 2)
turtle.penup()
turtle.setheading(29)
turtle.fd(size * 5.7)
turtle.color('black')
turtle.pensize(4)
turtle.pendown()
turtle.fd(size * 1.2)
# Show the countdown 3,2,1
def draw_0(i):
turtle.speed(0)
turtle.penup()
turtle.hideturtle() # Hide arrows to show
turtle.goto(-50, -100)
turtle.color('red')
write = turtle.write(i, font=(' Song style ', 200, 'normal'))
time.sleep(1)
# According to the text
def draw_1():
turtle.penup()
turtle.hideturtle() # Hide arrows to show
turtle.goto(-450, 0)
turtle.color('red')
write = turtle.write(' baby , Happy Valentine's Day ', font=(' Song style ', 60, 'normal'))
time.sleep(2)
# Little people who show love
def draw_2():
turtle.speed(3)
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(205, -100)
draw_heart(43)
turtle.hideturtle()
time.sleep(2)
def draw_3():
turtle.penup()
turtle.hideturtle() # Hide arrows to show
turtle.goto(-220, 50)
turtle.color('red')
write = turtle.write(' baby ', font=(' Song style ', 60, 'normal'))
turtle.penup()
turtle.goto(0, -50)
write = turtle.write(' baby ', font=(' Song style ', 60, 'normal'))
time.sleep(2)
# Show an arrow through the heart
def draw_4():
turtle.speed(1)
turtle.penup()
turtle.goto(-410, -200)
turtle.color('pink')
turtle.pendown()
turtle.write(' Princess Kitty Dog King ', font=('wisdom', 60, 'normal'))
turtle.speed(1)
turtle.penup()
turtle.color("red")
turtle.goto(-31, -220)
turtle.write('',font=('wisdom', 80, 'normal'))
arrow_heart(20, -60, 51)
turtle.showturtle()
4. Romantic pop-up painting
It's used here tkinter Module to draw a small pop-up window , Finally, I use for Loop to realize the repeatability and randomness of pop-up window , This is also the biggest innovation I think ! A lot of surprises , Full of heart and romance , Ha ha ha .
def dow():
window = tk.Tk()
width = window.winfo_screenwidth()
height = window.winfo_screenheight()
a = random.randrange(0, width)
b = random.randrange(0, height)
window.title(' baby !')
window.geometry("200x50" + "+" + str(a) + "+" + str(b))
tk.Label(window,
text=' I love you baby !', # Label text
bg='pink', # The background color
font=('..', 17), # Font and font size
width=18, height=2 # Label length and width
).pack() # Fixed window position
window.mainloop()
number=[3,2,1] # Store the countdown number on the display screen 1,2,3
if __name__ == '__main__':
turtle.setup(900, 500) # Adjust the size of the canvas
for i in number:
draw_0(i)
clear_screen()
draw_1()
clear_screen()
draw_2()
clear_screen()
draw_3()
clear_screen()
draw_4()
time.sleep(5)
# Pop up settings
threads = []
for i in range(200): # Number of cartridges required
t = threading.Thread(target=dow)
threads.append(t)
time.sleep(0.01)
threads[i].start()
3、 ... and 、 The source code to share
Here comes the source code :
# Time : 2022/2/14 12:21
# File : Valentine's Day .py
# Author : yes Dream ah !
# VX : Xu18300396393
# Ten thousand times sad , There will still be Dream, I've been waiting for you in the warmest place !
import turtle
import time
import random
import tkinter as tk
import threading
# Realization of clean screen
def clear_screen():
turtle.penup() # Brush up
turtle.goto(0,0) # Locate the (0,0)
turtle.color('white')
turtle.pensize(800) # Brush thickness
turtle.pendown() # The paintbrush falls
turtle.setheading(0) # Set orientation
turtle.fd(300) # Forward
turtle.bk(600) # back off
# Initialize the turtle's position
def go_start(x, y, state):
turtle.pendown() if state else turtle.penup()
turtle.goto(x, y)
# Draw line ,state When true, the turtle returns to the origin , When it's false, it doesn't go back to the original starting point
def draw_line(length, angle, state):
turtle.pensize(1)
turtle.pendown()
turtle.setheading(angle)
turtle.fd(length)
turtle.bk(length) if state else turtle.penup()
turtle.penup()
# Draw a picture of a little man who radiates love
def draw_people(x, y):
turtle.speed(0)
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.pensize(2)
turtle.color('black')
turtle.setheading(0)
turtle.circle(35, 360)
turtle.penup()
turtle.pensize(3)
turtle.setheading(90)
turtle.fd(45)
turtle.setheading(180)
turtle.fd(20)
turtle.setheading(0)
turtle.fd(35)
turtle.pendown()
turtle.circle(4, 360)
turtle.penup()
turtle.goto(x, y)
turtle.pensize(2)
turtle.setheading(0)
turtle.fd(20)
turtle.setheading(90)
turtle.fd(20)
turtle.setheading(-90)
turtle.pendown()
turtle.circle(5, 180)
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()
# Draw love
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()
turtle.speed(0)
# Draw arrow feathers
def draw_feather(size):
angle = 30 # The angle of the arrow
feather_num = size // 6 # The number of feathers
feather_length = size // 3 # The length of the feather
feather_gap = size // 10 # The spacing of feathers
for i in range(feather_num):
draw_line(feather_gap, angle + 180, False) # Arrow handle , No
draw_line(feather_length, angle + 145, True) # wing , To turn back
draw_line(feather_length, angle + 145, False)
draw_line(feather_num * feather_gap, angle, False)
draw_line(feather_length, angle + 145 + 180, False)
for i in range(feather_num):
draw_line(feather_gap, angle + 180, False) # Arrow handle , No
draw_line(feather_length, angle - 145, True) # wing , To turn back
draw_line(feather_length, angle - 145, False)
draw_line(feather_num * feather_gap, angle, False)
draw_line(feather_length, angle - 145 + 180, False)
# Draw an arrow through the heart , At last the head of the arrow was not drawn , Use turtles instead of
def arrow_heart(x, y, size):
go_start(x, y, False)
draw_heart(size * 1.15)
turtle.setheading(-150)
turtle.penup()
turtle.fd(size * 2.2)
draw_heart(size)
turtle.penup()
turtle.setheading(150)
turtle.fd(size * 2.2)
turtle.color('black')
draw_feather(size)
turtle.pensize(4)
turtle.setheading(30)
turtle.pendown()
turtle.fd(size * 2)
turtle.penup()
turtle.setheading(29)
turtle.fd(size * 5.7)
turtle.color('black')
turtle.pensize(4)
turtle.pendown()
turtle.fd(size * 1.2)
# Show the countdown 3,2,1
def draw_0(i):
turtle.speed(0)
turtle.penup()
turtle.hideturtle() # Hide arrows to show
turtle.goto(-50, -100)
turtle.color('red')
write = turtle.write(i, font=(' Song style ', 200, 'normal'))
time.sleep(1)
# According to the text
def draw_1():
turtle.penup()
turtle.hideturtle() # Hide arrows to show
turtle.goto(-450, 0)
turtle.color('red')
write = turtle.write(' baby , Happy Valentine's Day ', font=(' Song style ', 60, 'normal'))
time.sleep(2)
# Little people who show love
def draw_2():
turtle.speed(3)
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(205, -100)
draw_heart(43)
turtle.hideturtle()
time.sleep(2)
def draw_3():
turtle.penup()
turtle.hideturtle() # Hide arrows to show
turtle.goto(-220, 50)
turtle.color('red')
write = turtle.write(' baby ', font=(' Song style ', 60, 'normal'))
turtle.penup()
turtle.goto(0, -50)
write = turtle.write(' baby ', font=(' Song style ', 60, 'normal'))
time.sleep(2)
# Show an arrow through the heart
def draw_4():
turtle.speed(1)
turtle.penup()
turtle.goto(-410, -200)
turtle.color('pink')
turtle.pendown()
turtle.write(' Princess Kitty Dog King ', font=('wisdom', 60, 'normal'))
turtle.speed(1)
turtle.penup()
turtle.color("red")
turtle.goto(-31, -220)
turtle.write('',font=('wisdom', 80, 'normal'))
arrow_heart(20, -60, 51)
turtle.showturtle()
def dow():
window = tk.Tk()
width = window.winfo_screenwidth()
height = window.winfo_screenheight()
a = random.randrange(0, width)
b = random.randrange(0, height)
window.title(' baby !')
window.geometry("200x50" + "+" + str(a) + "+" + str(b))
tk.Label(window,
text=' I love you baby !', # Label text
bg='pink', # The background color
font=('..', 17), # Font and font size
width=18, height=2 # Label length and width
).pack() # Fixed window position
window.mainloop()
number=[3,2,1] # Store the countdown number on the display screen 1,2,3
if __name__ == '__main__':
turtle.setup(900, 500) # Adjust the size of the canvas
for i in number:
draw_0(i)
clear_screen()
draw_1()
clear_screen()
draw_2()
clear_screen()
draw_3()
clear_screen()
draw_4()
time.sleep(5)
# Pop up settings
threads = []
for i in range(200): # Number of cartridges required
t = threading.Thread(target=dow)
threads.append(t)
time.sleep(0.01)
threads[i].start()
Four 、 Best wishes
I hope everyone can be with the people they like on Valentine's day , Give her the one that belongs to her or His exclusive gift ! Happy everyday , Live your life , I've always been there ~( If you have any questions , Welcome to the comment area or private letter, I ow , I'll see it all !)
5、 ... and 、 Original project document sharing
If you really don't understand Python, Then download the compressed package directly and you can put , One click operation , You need to take it yourself :
Valentine's Day confession artifact exe file + Just run it directly
The articles ---- Good article recommends
I and CSDN Of 2021 -- From passers-by to a self-report of a Wanfen blogger
Python Public class ----Python It's very simple !
Christmas is coming , How can there be no Christmas tree Come and send her a special Christmas gift for her beloved ~
All right. , That's all I want to share with you today , See you next time !
️️️ If you like , Don't be stingy with your one key triple connection ~
边栏推荐
- How to handle wechat circle of friends marketing activities and share production and release skills
- Wechat applet quick start (including NPM package use and mobx status management)
- Global and Chinese market of full authority digital engine control (FADEC) 2022-2028: Research Report on technology, participants, trends, market size and share
- Basic knowledge of dictionaries and collections
- Sightseeing - statistics of the number of shortest paths + state transfer + secondary small paths
- Offset related concepts + drag modal box case
- String and+
- 19、 MySQL -- SQL statements and queries
- 4. Data splitting of Flink real-time project
- Bool blind note - score query
猜你喜欢
HCIA-USG Security Policy
How to modify the network IP addresses of mobile phones and computers?
C 10 new feature [caller parameter expression] solves my confusion seven years ago
How can the outside world get values when using nodejs to link MySQL
Promethus
Nerfplusplus parameter format sorting
How to do Taobao full screen rotation code? Taobao rotation tmall full screen rotation code
In 2021, the global foam protection packaging revenue was about $5286.7 million, and it is expected to reach $6615 million in 2028
Operate BOM objects (key)
MDM mass data synchronization test verification
随机推荐
[Yu Yue education] basic reference materials of manufacturing technology of Shanghai Jiaotong University
Blue Bridge Cup: the fourth preliminary - "simulated intelligent irrigation system"
[Yugong series] February 2022 Net architecture class 004 ABP vNext used in WPF project
Sightseeing - statistics of the number of shortest paths + state transfer + secondary small paths
Nacos usage of micro services
MySQL 8.0 data backup and recovery
AI enhanced safety monitoring project [with detailed code]
P5.js development - setting
Parental delegation mechanism
Sparse matrix (triple) creation, transpose, traversal, addition, subtraction, multiplication. C implementation
Change deepin to Alibaba image source
Teach you how to quickly recover data by deleting recycle bin files by mistake
MySQL learning notes - single table query
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of rotary tablet presses in the global market in 2022
Micro service knowledge sorting - cache technology
In 2021, the global revenue of thick film resistors was about $1537.3 million, and it is expected to reach $2118.7 million in 2028
An old programmer gave it to college students
2.6 formula calculation
First knowledge of database
7. Data broker presentation