@wudawufanfan
2016-09-25T11:48:26.000000Z
字数 2412
阅读 706
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 osimport timedef 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 osimport mathimport timedef read_initial(initial_file): ######## read the initial.txt and transfer it into a 2d listitxt= 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_screendef rotation(angle,xscreen,l2,s,x_):if (angle != 0):for j in range(l2):if (xscreen[x_][j] == s):radius = j - 60x = int(radius*math.cos(angle*math.pi/180))+60y = int(radius*math.sin(angle*math.pi/180))+x_xscreen[y][x] = xscreen[x_][j]xscreen[x_][j] = ' 'else:passreturn xscreenelse:return xscreendef 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 - 12minutes = 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.