Advertisement
yclee126

knight path fill

Feb 14th, 2021 (edited)
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. # was just curious how the patterns will appear
  4.  
  5. import ctypes
  6. ctypes.windll.user32.SetProcessDPIAware()
  7. import cv2
  8. import numpy as np
  9.  
  10. def step(canvas, x, y, iter):
  11. h, w, _ = canvas.shape
  12. if x < 0 or y < 0 or x >= w or y >= h or iter < 0:
  13. return
  14. canvas[y][x] *= 0
  15. for i in range(8):
  16. di = int(i/1%2)
  17. xs = int((int(i/2%2))*2 - 1)
  18. ys = int((int(i/4%2))*2 - 1)
  19. step(canvas, x+int(1+di)*xs, y+int(2-di)*ys, iter-1)
  20.  
  21. canvas = np.ones((100, 100, 3))
  22. for i in range(5):
  23. step(canvas, 50, 50, i)
  24. canvas2 = cv2.resize(canvas, dsize=(0, 0), fx=4, fy=4, interpolation=cv2.INTER_NEAREST)
  25. cv2.imshow('image', canvas2)
  26. cv2.waitKey(1000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement