# import cv2
# import numpy as np
# import random
#
# image = np.ones((500,500,3), dtype=np.uint8)*225
#
# red_points = []
# blue_points = []
#
# for _ in range(5):
# 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)
#
#
# while True:
#
# if cv2.waitKey(1) & 0xFF == 27:
#
# break
#
# cv2.destroyAllWindows()
import cv2
import numpy as np
import random
# 캔버스 생성
canvas = np.ones((500, 500, 3), dtype="uint8") * 255
# 랜덤한 위치에 빨간색 점 5개 소환
red_points = [(random.randint(0, 499), random.randint(0, 499)) for _ in range(5)]
for point in red_points:
cv2.circle(canvas, point, 3, (0, 0, 255), -1)
# 랜덤한 위치에 파란색 점 5개 소환
blue_points = [(random.randint(0, 499), random.randint(0, 499)) for _ in range(5)]
for point in blue_points:
cv2.circle(canvas, point, 3, (255, 0, 0), -1)
# 랜덤한 위치에 초록색 점 소환
green_point = (random.randint(0, 499), random.randint(0, 499))
cv2.circle(canvas, green_point, 3, (0, 255, 0), -1)
# 반지름 입력받기
radius = int(input("원의 반지름을 입력하세요(10의 배수): "))
# 초록색 점 주위에 원 그리기
cv2.circle(canvas, green_point, radius, (0, 225, 0), 0)
# 원을 그리기 - 반지름을 50씩 증가하며 7개의 원
thickness = 1 # 테두리 두께 설정
for i in range(50): # 7개의 원
radius = (i + 1) * 10 # 반지름은 50씩 증가
# 테두리를 픽셀 단위로 처리
red_count = 0
blue_count = 0
for x in range(500):
for y in range(500):
distance_to_center = np.sqrt((x - green_point[0])**2 + (y - green_point[1])**2)
if radius - thickness <= distance_to_center <= radius + thickness:
# 빨간색 및 파란색 점과의 거리 계산
distances_red = [np.linalg.norm(np.array(point) - np.array([x, y])) for point in red_points]
distances_blue = [np.linalg.norm(np.array(point) - np.array([x, y])) for point in blue_points]
# 가까운 점의 색상에 따라 카운트 증가
if min(distances_red) < min(distances_blue):
red_count += 1
else:
blue_count += 1
# 테두리 색상 결정: 빨간색 픽셀이 더 많으면 빨간색, 파란색이 더 많으면 파란색
final_color = (0, 0, 255) if red_count > blue_count else (255, 0, 0)
cv2.circle(canvas, green_point, radius, final_color, thickness)
# 결과 출력
cv2.imshow("Canvas", canvas)
cv2.waitKey(0)
cv2.destroyAllWindows()
# # 원을 그리기 - 반지름을 50씩 증가하며 7개의 원
# thickness = 2 # 테두리 두께 설정
# for i in range(10): # 7개의 원
# radius = (i + 1) * 20 # 반지름은 50씩 증가
#
# # 원의 테두리 영역을 색칠하기
# for x in range(500):
# for y in range(500):
# distance_to_center = np.sqrt((x - green_point[0]) ** 2 + (y - green_point[1]) ** 2)
# if radius - thickness <= distance_to_center <= radius + thickness:
# # 빨간색 및 파란색 점과의 거리 계산
# distances = {
# 'red': min((np.linalg.norm(np.array(point) - np.array([x, y])) for point in red_points)),
# 'blue': min((np.linalg.norm(np.array(point) - np.array([x, y])) for point in blue_points))
# }
# # 가까운 점의 색상 선택
# nearest_color = 'red' if distances['red'] < distances['blue'] else 'blue'
#
# # 현재 원에 대해 테두리를 단일 색상으로 칠하기
# if nearest_color == 'red':
# canvas[y, x] = (0, 0, 255) # 빨간색으로 칠하기
# else:
# canvas[y, x] = (255, 0, 0) # 파란색으로 칠하기
#
# # 결과 출력
# cv2.imshow("Canvas", canvas)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
#



