Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- from PIL import Image, ImageDraw
- new_img = Image.new("RGB", (1001,1001),"white")
- #new_img.show()
- #def direction(m):
- #return (m%2)*-( math.floor(m/3)*2-1 ), ( (m+1)%2 )*-( math.floor(m/3)*2-1 )
- def simple(n):
- #if i in {1,2}: return True;
- for i in range ( 2,round( math.sqrt(n) )+1 ):
- if n%i == 0:
- return False
- return True
- n = int( input("Enter not even number: ") )
- matrix = []
- for i in range(n):
- matrix.append([0]*n)
- x, y = 0, 0
- dx, dy = 1, 0
- dir = 1
- for i in range(n*n):
- matrix[x][y] = n*n - i
- x += dx
- y += dy
- if (x+dx >= n) or (x+dx < 0) or (y+dy >= n) or (y+dy < 0) or matrix[x+dx][y+dy]:
- dx, dy = -dy, dx
- #for i in range(n):
- #for j in range(n):
- #print(f"{matrix[i][j]:>4}",end="")
- #pass
- #print()
- for i in range(n):
- for j in range(n):
- if simple(matrix[i][j]):
- #print(f"\033[31m()", end="")
- pencil = ImageDraw.Draw(new_img)
- pencil.rectangle((i,j,i+1,j+1),fill="black")
- #else:
- #print(f"\033[36m<>", end="")
- #pass
- #print()
- #print(f"\033[0m", end="")
- new_img.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement