在同一个循环中,也可以遍历四个斜着的临近点
for i in [-1,1]: for j in [-1,1]: # top,left,right,bottom nx, ny = x+(i+j)//2,y+(i-j)//2 # corners nx, ny = x+i,y+j
以前都是写死 x+1,y x,y+1... 然后遍历,或者用三角函数循环角度,感觉上面写更简洁