93 lines
3.2 KiB
Python
93 lines
3.2 KiB
Python
from PIL import Image, ImageDraw
|
|
import math
|
|
|
|
# 아이콘 이미지 사이즈 (픽셀)
|
|
size = (512, 512)
|
|
|
|
# 새 이미지를 투명 배경(RGBA)으로 생성
|
|
img = Image.new("RGBA", size, (255, 255, 255, 0))
|
|
draw = ImageDraw.Draw(img)
|
|
|
|
# 색상 정의
|
|
lens_color = (100, 149, 237, 255) # 옅은 파란색 (돋보기 렌즈 채움색)
|
|
lens_outline = (50, 50, 50, 255) # 진한 회색 (돋보기 테두리)
|
|
handle_color = (80, 80, 80, 255) # 어두운 회색 (돋보기 손잡이)
|
|
exclamation_color = (255, 69, 0, 255) # 붉은색 (느낌표)
|
|
|
|
# --- 1. 돋보기 렌즈 (원) 그리기 ---
|
|
lens_center = (256, 256) # 이미지 중앙
|
|
lens_radius = 150 # 렌즈의 반지름
|
|
|
|
# 원(타원) 좌표: (좌상, 우하)
|
|
lens_bbox = (
|
|
lens_center[0] - lens_radius,
|
|
lens_center[1] - lens_radius,
|
|
lens_center[0] + lens_radius,
|
|
lens_center[1] + lens_radius
|
|
)
|
|
# 채움 색상과 테두리 두께 지정
|
|
draw.ellipse(lens_bbox, fill=lens_color, outline=lens_outline, width=8)
|
|
|
|
# --- 2. 돋보기 손잡이 그리기 ---
|
|
# 손잡이는 렌즈 오른쪽 아래쪽에서 시작하여 45도 각도로 뻗어나갑니다.
|
|
angle = 45 # 손잡이 각도 (45도)
|
|
handle_length = 180 # 손잡이 길이
|
|
handle_width = 30 # 손잡이 두께
|
|
|
|
# 렌즈 테두리의 끝점: 렌즈의 45도 지점 계산
|
|
theta = math.radians(angle)
|
|
start_x = lens_center[0] + lens_radius * math.cos(theta)
|
|
start_y = lens_center[1] + lens_radius * math.sin(theta)
|
|
|
|
# 손잡이 끝점
|
|
end_x = lens_center[0] + (lens_radius + handle_length) * math.cos(theta)
|
|
end_y = lens_center[1] + (lens_radius + handle_length) * math.sin(theta)
|
|
|
|
# 손잡이를 사각형(회전한 형태)로 표현하기 위해, 수직(법선) 방향 벡터 계산
|
|
dx = end_x - start_x
|
|
dy = end_y - start_y
|
|
length = math.hypot(dx, dy)
|
|
offset_x = -dy/length * (handle_width/2)
|
|
offset_y = dx/length * (handle_width/2)
|
|
|
|
# 사각형 네 꼭짓점 계산
|
|
p1 = (start_x + offset_x, start_y + offset_y)
|
|
p2 = (start_x - offset_x, start_y - offset_y)
|
|
p3 = (end_x - offset_x, end_y - offset_y)
|
|
p4 = (end_x + offset_x, end_y + offset_y)
|
|
|
|
draw.polygon([p1, p2, p3, p4], fill=handle_color)
|
|
|
|
# --- 3. 돋보기 렌즈 내부에 느낌표 그리기 ---
|
|
# 느낌표는 중앙에 큰 직사각형과 아래쪽에 작은 원(점)으로 구성합니다.
|
|
# 느낌표의 중심 좌표 및 크기 설정
|
|
exclamation_center = (256, 230)
|
|
exclamation_height = 80
|
|
exclamation_width = 20
|
|
|
|
# 느낌표 막대: 사각형 좌표
|
|
ex_mark_top_left = (
|
|
exclamation_center[0] - exclamation_width // 2,
|
|
exclamation_center[1] - exclamation_height // 2
|
|
)
|
|
ex_mark_bottom_right = (
|
|
exclamation_center[0] + exclamation_width // 2,
|
|
exclamation_center[1] + exclamation_height // 2
|
|
)
|
|
draw.rectangle([ex_mark_top_left, ex_mark_bottom_right], fill=exclamation_color)
|
|
|
|
# 느낌표 점: 원을 그림
|
|
dot_radius = 12
|
|
dot_center = (256, 300)
|
|
dot_bbox = (
|
|
dot_center[0] - dot_radius,
|
|
dot_center[1] - dot_radius,
|
|
dot_center[0] + dot_radius,
|
|
dot_center[1] + dot_radius
|
|
)
|
|
draw.ellipse(dot_bbox, fill=exclamation_color)
|
|
|
|
# --- 4. 아이콘 파일 저장 ---
|
|
img.save("app_icon.png")
|
|
print("아이콘 파일 'app_icon.png'이 생성되었습니다.")
|