Advertisement
Oppaceted

Ulama_1

Oct 28th, 2023
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. import math
  2. from PIL import Image, ImageDraw
  3.  
  4. new_img = Image.new("RGB", (1001,1001),"white")
  5. #new_img.show()
  6.  
  7. #def direction(m):
  8.     #return (m%2)*-( math.floor(m/3)*2-1 ), ( (m+1)%2 )*-( math.floor(m/3)*2-1 )
  9.  
  10. def simple(n):
  11.     #if i in {1,2}: return True;
  12.     for i in range ( 2,round( math.sqrt(n) )+1 ):
  13.         if n%i == 0:
  14.             return False
  15.     return True
  16.  
  17. n = int( input("Enter not even number: ") )
  18. matrix = []
  19. for i in range(n):
  20.     matrix.append([0]*n)
  21.  
  22. x, y = 0, 0
  23. dx, dy = 1, 0
  24. dir = 1
  25. for i in range(n*n):
  26.     matrix[x][y] = n*n - i
  27.     x += dx
  28.     y += dy
  29.     if (x+dx >= n) or (x+dx < 0) or (y+dy >= n) or (y+dy < 0) or matrix[x+dx][y+dy]:
  30.         dx, dy = -dy, dx
  31. #for i in range(n):
  32.     #for j in range(n):
  33.         #print(f"{matrix[i][j]:>4}",end="")
  34.         #pass
  35.     #print()
  36. for i in range(n):
  37.     for j in range(n):
  38.         if simple(matrix[i][j]):
  39.             #print(f"\033[31m()", end="")
  40.             pencil = ImageDraw.Draw(new_img)
  41.             pencil.rectangle((i,j,i+1,j+1),fill="black")
  42.         #else:
  43.             #print(f"\033[36m<>", end="")
  44.             #pass
  45.     #print()
  46. #print(f"\033[0m", end="")
  47. new_img.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement