I made a memorial service because I made something that I didn't have.
I tried to reproduce the emergency escape program that appears in the movie "The Disappearance of Haruhi Suzumiya".
As in the work, the characters are output one by one in order.
The end of the code ends with "input ()", so when you press the enter key, the prompt disappears. During the work, Kyon returned from the altered world the moment he pressed the enter key, the people who were supposed to be in the club room disappeared, and the prompt that was supposed to be on the PC screen disappeared.
As expected, I couldn't write a program to erase the people around me, but I made it possible to erase the prompt with the enter key, so I feel like I've moved from the modified world to play alone.
from time import sleep
#The character given to the argument is YUKI.Display like N
def yuki_n(*message, speed=0.15):
count = 0 #Variable to assign after what line has been output
name = "YUKI. N>"
#Processing to be performed on the output of the first line
msg = message[0]
#Show name
for s in range(len(name)):
print(name[0:s+1]+"\r",end="")
sleep(speed)
for i in range(len(msg)):
#For the last character of a line, do not add _ at the end of the sentence
if i == len(msg)-1:
print(name + msg)
sleep(speed)
count += 1
else:
print(name + msg[0:i+1],end="")
print("_"+"\r",end="")
sleep(speed)
#Processing to be performed if there is output from the second line onward
if len(message) > 1:
for msg in message[1:]:
for i in range(len(msg)):
#For the last character of a line, do not add _ at the end of the sentence
if i == len(msg)-1:
print(" " + msg)
sleep(speed)
count += 1
else:
print(" " + msg[0:i+1],end="")
print("_"+"\r",end="")
sleep(speed)
#Line break after printing the last line
if count == len(message):
print("")
#Display "Ready?"
def ready(speed=0.5):
ready = "Ready?"
#「_Flashes
for _ in range(2):
print(" " + "_"+"\r",end="")
sleep(speed)
print(" " + " "+"\r",end="")
sleep(speed)
print(" " + "_"+"\r",end="")
sleep(speed)
for s in range(len(ready)):
print(" " + ready[0:s] + "_" + "\r",end="")
sleep(0.15)
print(" " + ready,end="")
#When starting a new line, use yuki as multiple arguments_pass to n function
yuki_n("When you are reading this","I will not be me.")
yuki_n("If this message is displayed,","There you, me, Haruhi Suzumiya, Mikuru Asahina,","Kazuki Koizumi should exist.")
yuki_n("That is the key.","You have found the answer.")
yuki_n("This is an emergency escape program."," ","To start it, press the enter key,","If not, select another key."," ","When started,"\
,"You get the opportunity to correct space-time.","However, success cannot be guaranteed.","In addition, we cannot guarantee the return.")
yuki_n("This program only starts once.","After execution, it will be erased."," ","If non-execution is selected, it will be deleted without starting."," ")
ready()
input()
It's a simple program that just uses a carriage return. For how to use the carriage return, refer to "How to display the terminal output of the print function in Python by overwriting one line". became.
Since the character output is a function called "yuki_n", it depends on the character passed to the argument. You can also do something like that. It's not "Ready?" It's scary.
Recommended Posts