Guest User

tetrascope

a guest
Nov 6th, 2020
49
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. from PIL import Image
  3.  
  4. R = 2048
  5. D = 2*R
  6.  
  7. def hex_to_rgb(value):
  8. lv = len(value)
  9. return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))
  10.  
  11. def hex_to_str(c):
  12. c = c.lstrip('0x')
  13. if len(c) <= 6:
  14. #return c.zfill(6)
  15. return c.ljust(6, '0')
  16. else:
  17. return c.substring(0, 3) + c.substring(c.length-3)
  18.  
  19. data = np.zeros((D,D,3), dtype=np.uint8)
  20. sqrR = R*R
  21. for x in range(0, R):
  22. if not x % 128:
  23. print(x, " rows rendered")
  24. for y in range (x, R):
  25. sqr = (x*x+y*y)
  26. if sqr <= sqrR:
  27. rgbtuple = hex_to_rgb(hex_to_str(hex(sqr)))
  28. data[R+x,R+y] = rgbtuple
  29. data[R+x,R-y] = rgbtuple
  30. data[R-x,R+y] = rgbtuple
  31. data[R-x,R-y] = rgbtuple
  32. data[R+y,R+x] = rgbtuple
  33. data[R+y,R-x] = rgbtuple
  34. data[R-y,R+x] = rgbtuple
  35. data[R-y,R-x] = rgbtuple
  36.  
  37. img = Image.fromarray(data)
  38. img.save("test.png")
RAW Paste Data