-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathp04.py
30 lines (27 loc) · 762 Bytes
/
p04.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from common import *
def square_spiral(shape,num_cycles):
w,b=np.ones(shape,dtype=np.uint8),np.zeros(shape,dtype=np.uint8)
im=np.hstack((b,w))
z=[[w,b],[w,b],[b,w],[b,w]]
for i in range(2,3+num_cycles):
j=(i-2)%4
if i<2+num_cycles:
im=np.vstack((np.kron([1]*i,z[j][0]),im,np.kron([1]*i,z[j][1])))
else:
im=np.vstack((np.kron([1]*i,z[j][0]),im))
im=im.T
return im
def draw(**kwargs):
s=square_spiral((4,4),10)
s1=1-s.T[...,::-1]
s2=s1[::-1,::-1]
s2=s2[...,5:]
q=np.hstack((s1,s2))
q[-4:,...]=1
q=np.vstack((q,q[...,::-1]))
im=imtile(q,np.array(q.shape)*10)
return im
if __name__ == '__main__':
im=draw()
imshow(im)
imsave(im,'p04.png')