#nice job
# a, b = map(int, input().split())
# matrix = []
# for i in range(b):
# k = [0]*a
# matrix.append(k)
# for i in range(0, b):
# for j in range(0, a):
# c = 0
# matrix[0][0] = 1
# if i == 0:
# matrix[i][j] = matrix[i][j-1]
# elif j == 0:
# matrix[i][j] = matrix[i-1][j]
# else:
# matrix[i][j] = matrix[i - 1][j] + matrix[i][j - 1]
# c += matrix[i][j]
# print(c % 100000000)
####################################################################
################### advanced #######################################
import matplotlib.pyplot as plt
import numpy as np
import cv2
# import cv2
# import numpy as np
#
# # 500x500 크기의 하얀색 이미지를 생성
# white_image = np.ones((500, 500, 3), dtype=np.uint8) * 255
#
# # 생성된 이미지를 화면에 표시
# cv2.imshow('White Image', white_image)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
### MISSION ###
'''
1. Generate 500x500 image
2. Draw 5 dots(red, blue) - random locate (how random make?)
3. Draw 1 dots(Green) - random
4.
'''
import cv2
import numpy as np
import random
# 500x500 크기의 흰색 이미지 생성
image = np.ones((500, 500, 3), dtype=np.uint8) * 255
# 빨간색 및 파란색 점 생성
red_points = []
blue_points = []
for _ in range(5): # 총 10개의 점 생성
x_red, y_red = random.randint(0, 499), random.randint(0, 499)
x_blue, y_blue = random.randint(0, 499), random.randint(0, 499)
red_points.append((x_red, y_red))
blue_points.append((x_blue, y_blue))
cv2.circle(image, (x_red, y_red), radius=5, color=(0, 0, 255), thickness=-1) # 빨간색 점
cv2.circle(image, (x_blue, y_blue), radius=5, color=(255, 0, 0), thickness=-1) # 파란색 점
# 초록색 점 생성
x_green, y_green = random.randint(0, 499), random.randint(0, 499)
cv2.circle(image, (x_green, y_green), radius=5, color=(0, 255, 0), thickness=-1) # 초록색 점
# 사용자로부터 반지름 입력받기
radius = int(input("원의 반지름을 입력하세요: "))
# 원 안에 포함된 점 계산
red_count = sum((x - x_green)**2 + (y - y_green)**2 <= radius**2 for x, y in red_points)
blue_count = sum((x - x_green)**2 + (y - y_green)**2 <= radius**2 for x, y in blue_points)
# 빨간색과 파란색 점 개수가 같을 때 가까운 점의 색 결정
if red_count == blue_count:
closest_red_dist = min((x - x_green)**2 + (y - y_green)**2 for x, y in red_points)
closest_blue_dist = min((x - x_green)**2 + (y - y_green)**2 for x, y in blue_points)
circle_color = (0, 0, 255) if closest_red_dist < closest_blue_dist else (255, 0, 0)
else:
# 빨간색 점이 더 많으면 빨간색, 아니면 파란색
circle_color = (0, 0, 255) if red_count > blue_count else (255, 0, 0)
# 초록색 점 주위의 원 그리기
cv2.circle(image, (x_green, y_green), radius=radius, color=circle_color, thickness=2)
# 결과 출력
if red_count > blue_count:
print("빨간색 점이 더 많습니다! 원의 색깔은 빨간색입니다.")
elif blue_count > red_count:
print("파란색 점이 더 많습니다! 원의 색깔은 파란색입니다.")
else:
print("빨간색과 파란색 점의 개수가 같습니다!")
print(f"초록색 점에 더 가까운 점의 색깔로 원이 결정되었습니다. 원의 색깔은 {'빨간색' if circle_color == (0, 0, 255) else '파란색'}입니다.")
# 이미지 화면에 표시
cv2.imshow('Result', image)
# ESC를 누를 때까지 창이 열려 있음
while True:
if cv2.waitKey(1) & 0xFF == 27: # ESC 키를 누르면 종료
break
cv2.destroyAllWindows()