- width,height=100,50 #宽高
- matrix=[["" for x in range(width)] for y in range(height)]
- DDD={(0,0):list("┌"),(0,1):list("│└├"),(1,0):list("─┐┬"),(1,1):list("┘┤┴┼")}
- EL="│┐┘┤" #不能接左
- UL="─└┘┴" #不能连上
- import random
- for c in range(height):
- for r in range(width):
- UUU=0 if c==0 or matrix[c-1][r] in UL else 1
- LLL=0 if r==0 or matrix[c][r-1] in EL else 1
- matrix[c][r]=random.choice(DDD[(LLL,UUU)])
- txt="\\n".join(["".join(x) for x in matrix])
- print(txt)
- from time import sleep
- sleep(100)
- #该片段来自于http://www.codesnippet.cn/detail/020120148370.html
来源: http://www.codesnippet.cn/detail/020120148370.html