马说
【唐】韩愈
不是真的文章,只是 Python 代码。
“马”指的是象棋中的马。
d=[(1,2),(2,1),(-1,2),(-2,1),(1,-2),(2,-1),(-1,-2),(-2,-1)]
b=[[-1 for i in range(404)] for i in range(404)]
que=[(1,1),]
b[1][1]=0
while que:
h=que.pop(0)
for i in d:
x=h[0]+i[0]
y=h[1]+i[1]
if x>201 or y>201 or x<0 or y<0 or b[x][y]!=-1:
continue
que.append((x,y))
b[x][y]=b[h[0]][h[1]]+1
import turtle,time
turtle.colormode(255)
turtle.ht()
turtle.pu()
turtle.tracer(False)
for t in range(0,30):
for i in range(1,41):
for j in range(1,41):
#print(b[i][j],end=' ')
if b[i][j]==t:
li=b[i][j]*9
turtle.fillcolor(li,li,li)
turtle.goto(i*10-200,j*10-200)
turtle.begin_fill()
for k in range(4):
turtle.rt(90)
turtle.fd(10)
turtle.end_fill()
#print()
turtle.update()
#turtle.clear()
time.sleep(0.2)
turtle.done()效果:(颜色越浅,数值越大)
