@wudawufanfan
2016-09-25T11:48:26.000000Z
字数 2412
阅读 636
python
Usually,we think computer language is a boring thing.In order to figure out a thing,programmer will type too many lines of codes without any mistake.But today's problem is to make the static character move on the screen.It's a really funny thing to do!
Use any means to make your English name or anything like it move.
The following is the code
import os
import time
def benpaobalanxiang():
for i in range(150):
print('wu fanfan\n')
print(' '*i+' ___')
print(' '*i+' /======/')
print(' '*i+' ____ // \___ ,/')
print(' '*i+' | \\ // :, ./')
print(' '*i+' |_______|__|_// ;:; /')
print(' '*i+' |_______|__|_// ;:; /')
print(' '*i+' _L_____________\o ;;;/')
print(' '*i+'____(CCCCCCCCCCCCCC)____________-/_____________________')
time.sleep( 0.2 )
os.system("cls")
time.sleep( 10 )
benpaobalanxiang()
we can make the printed praph move from left to right
[如图所示][ ]
We can let the figure move from left to right.Using the same way we can move anything like this.
The code is the following
First,make a initial.txt
[文件样式][]
the next is the code
import os
import math
import time
def read_initial(initial_file): ######## read the initial.txt and transfer it into a 2d list
itxt= open(initial_file)
initial_screen=[]
for lines in itxt.readlines():
lines=lines.replace("\n","").split(",")
initial_screen.append(lines)
itxt.close()
for i in range(len(initial_screen)):
initial_screen[i].extend(initial_screen[i][0])
del initial_screen[i][0]
return initial_screen
def rotation(angle,xscreen,l2,s,x_):
if (angle != 0):
for j in range(l2):
if (xscreen[x_][j] == s):
radius = j - 60
x = int(radius*math.cos(angle*math.pi/180))+60
y = int(radius*math.sin(angle*math.pi/180))+x_
xscreen[y][x] = xscreen[x_][j]
xscreen[x_][j] = ' '
else:
pass
return xscreen
else:
return xscreen
def output_screen(l,w,oscreen):
final_screen = [' ']*(w-1)
for i in range( w-1):
for j in range(l-1):
final_screen[i] = final_screen[i]+oscreen[i][j]
print (final_screen[i])
print ('\n')
def main():
while True:
hours = time.localtime(time.time())[3]
if (hours >=12):
hours = hours - 12
minutes = time.localtime(time.time())[4]
seconds = time.localtime(time.time())[5]
iscreen = read_initial('initial.txt')
length = len(iscreen[0])
width = len(iscreen)
fscreen = rotation(((hours+minutes/60)*30)-90,rotation((minutes*6)-90,rotation((seconds*6)-90,iscreen,length,'^',23),length,'*',22),length,'$',21)
output_screen(length,width,fscreen)
time.sleep(0.5)
os.system('cls')
main()
the result is
[动图节选][]
Thank Caihao for his hint.
1、Use the "import os i=os.systerm('cls')" to clean the screen
2、add space before each line to make the character move
Thank Chengfen liu yutao for their reminder.