요즘 내가 무슨 바람이 불었는지 시나리오는
팽개치고 프로그램 언어 공부를 한답시고
유튜브 강의를 하루 5시간씩 보고 있다.
엑셀 VBA는 예전에 터득해서 이미 작품도?
하나 만들었지만 파이썬이나 인공지능이 궁금해
꾸역꾸역 듣고 있는데
뜬금없이 유튜브 쑈츠에 말로만 코딩이 가능
하다는 내용이 있길레... 나도 도전! ㅎ
그리고 AI 와 대화하며 두시간만에 앱을 하나
뚝딱 만들었다.
아~ 물론 앱은 AI가 만들었고 나는 방향만 지정
하는 방식이다 , 예를 들자면 이렇게 명령....
1. 구슬 12개가 경주하는 앱을 만들어
2. 출발은 왼쪽에서 시작, 오른쪽에 결승점
3. 구슬 색은 빨강, 노랑, 파랑....
4. 거리는 팝업창으로 내가 입력할게
이정도 하면 신기하게 구슬이 움직이는 앱이
나오는데 여기에 약간의 양념을 친다, 물론 말로
5. 각각의 구슬 속도는 다르게 해
6. 트렉을 욕상 경기장처럼 타원으로 해
7. 11, 12번 구슬은 모양이 다르게 해
8. 타원을 돌때 외곽 구슬 속도 보정해
이렇게 명령 한번 할 때마다 군말없이
에러 메세지 없는 코딩이 착착된다.
햐~ 이걸로 두시간 노니 내가 지금까지 왜 코딩을
공부하고 있나 회의감이 들고..
조만간 '프로그래머, 개발자'라는 직업도 사라질듯한
예감이 든다..
물론 영화계도 그 여파를 벗어나지 못해
스턴트,, 엑스트라, 미술 모두 AI가 담당할 것이고
AI가 점령하는 그 자리에 있던 사람들은....
앞으로 다들 뭐해 먹고 살까?
총만 안들었을뿐 더 잔인하게 인간의 생활을
말살하니 터미네이터의 스카이넷이 실화가 된 느낌...
참고로 내가 한 명령을 AI가 작성한 코드
import pygame
import sys
import random
import tkinter as tk
from tkinter import simpledialog
import math
# Pygame 초기화
pygame.init()
# 팝업창으로 거리 입력 받기
root = tk.Tk()
root.withdraw()
distance = simpledialog.askinteger("거리 입력", "경주 거리를 입력하세요 (미터):",
minvalue=900, maxvalue=2000)
if distance is None:
sys.exit()
# 화면 설정
screen_info = pygame.display.Info()
SCREEN_WIDTH = screen_info.current_w
SCREEN_HEIGHT = 800
TRACK_START_Y = 50
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption(f"{distance}m 구슬 경주")
# 색상 정의
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)
GREEN = (0, 255, 0)
BROWN = (139, 69, 19)
PINK = (255, 192, 203)
PURPLE = (128, 0, 128)
SKY_BLUE = (135, 206, 235)
GRAY = (200, 200, 200)
# 구슬 색상 리스트
BALL_COLORS = [
WHITE, # 1번 흰색
YELLOW, # 2번 노랑
RED, # 3번 빨강
BLACK, # 4번 검정
BLUE, # 5번 파랑
GREEN, # 6번 초록
BROWN, # 7번 브라운
PINK, # 8번 분홍
PURPLE, # 9번 보라
SKY_BLUE, # 10번 하늘색
'SQUARE_WHITE', # 11번 흰색 사각형
'SQUARE_YELLOW' # 12번 노랑 사각형
]
# 트랙 설정
TRACK_WIDTH = SCREEN_WIDTH - 100
TRACK_HEIGHT = SCREEN_HEIGHT - TRACK_START_Y - 50
BASE_CURVE_RADIUS = 150 # U자 모양을 위한 반지름
TRACK_LANE_WIDTH = 2 # 구슬 간격 줄임
# 시간과 속도 계산
SIMULATION_TIME = 35
total_track_length = distance
pixels_per_meter = (TRACK_WIDTH - 100) / distance
# 선 설정 (결승점 기준으로 역순 계산)
finish_line_x = SCREEN_WIDTH // 2
curve_end_x = finish_line_x - 400
curve_start_x = curve_end_x
start_line_x = curve_start_x + (distance - 850)
def calculate_track_position(distance_covered, lane):
"""트랙 위의 위치 계산"""
straight1_length = distance - 850
curve_length = BASE_CURVE_RADIUS * math.pi
straight2_length = 400
if distance_covered < straight1_length: # 첫 직선 구간
x = start_line_x - distance_covered
y = TRACK_START_Y + (lane * TRACK_LANE_WIDTH)
elif distance_covered < straight1_length + curve_length: # U자 반원 구간
curve_distance = distance_covered - straight1_length
angle = (curve_distance / curve_length) * math.pi
center_x = curve_start_x
center_y = TRACK_START_Y + BASE_CURVE_RADIUS
# 반원 시작점을 90도 앞에서 시작하고 시계 방향으로 회전
x = center_x + BASE_CURVE_RADIUS * math.cos(-angle - math.pi/2)
y = center_y + BASE_CURVE_RADIUS * math.sin(-angle - math.pi/2) + (lane * TRACK_LANE_WIDTH)
else: # 마지막 직선 구간
remaining = distance_covered - (straight1_length + curve_length)
x = curve_end_x + remaining
y = TRACK_START_Y + 2 * BASE_CURVE_RADIUS + (lane * TRACK_LANE_WIDTH)
return x, y
def draw_tracks():
# 상단 정보 영역 구분선
pygame.draw.line(screen, BLACK, (0, TRACK_START_Y - 10), (SCREEN_WIDTH, TRACK_START_Y - 10), 2)
# U자 모양 트랙 그리기
# 첫 직선 구간
pygame.draw.line(screen, BLACK,
(curve_start_x, TRACK_START_Y),
(start_line_x, TRACK_START_Y), 1)
# U자 반원 구간 (시계 방향)
rect = pygame.Rect(curve_start_x - BASE_CURVE_RADIUS,
TRACK_START_Y,
2 * BASE_CURVE_RADIUS,
2 * BASE_CURVE_RADIUS)
pygame.draw.arc(screen, BLACK, rect, math.pi/2, 3*math.pi/2, 1)
# 마지막 직선 구간
pygame.draw.line(screen, BLACK,
(curve_end_x, TRACK_START_Y + 2 * BASE_CURVE_RADIUS),
(finish_line_x, TRACK_START_Y + 2 * BASE_CURVE_RADIUS), 1)
# 출발선과 결승선
pygame.draw.line(screen, BLUE, (start_line_x, TRACK_START_Y - 5),
(start_line_x, TRACK_START_Y + 5), 2)
pygame.draw.line(screen, RED, (finish_line_x, TRACK_START_Y + 2 * BASE_CURVE_RADIUS - 5),
(finish_line_x, TRACK_START_Y + 2 * BASE_CURVE_RADIUS + 5), 2)
# 거리 표시
section_distance = 200
total_sections = distance // section_distance
for i in range(1, total_sections):
current_distance = i * section_distance
if current_distance < distance - 850:
x = start_line_x - (current_distance * pixels_per_meter)
y = TRACK_START_Y
pygame.draw.line(screen, GRAY, (x, y - 5), (x, y + 5), 1)
distance_text = f"{current_distance}m"
font = pygame.font.Font(None, 20)
text = font.render(distance_text, True, BLACK)
screen.blit(text, (x - 15, y - 20))
# 시간 및 거리 정보 표시
elapsed_time = (pygame.time.get_ticks() - start_time) / 1000
time_text = f"Time: {elapsed_time:.1f}s"
distance_info = f"Distance: {distance}m"
font = pygame.font.Font(None, 30)
screen.blit(font.render(time_text, True, BLACK), (10, 10))
screen.blit(font.render(distance_info, True, BLACK), (200, 10))
# 구슬 초기화
ball_radius = 4
balls = []
for i in range(12):
base_speed = total_track_length / (SIMULATION_TIME * 60)
random_factor = random.uniform(0.95, 1.05)
balls.append({
'x': start_line_x,
'y': TRACK_START_Y + (i * TRACK_LANE_WIDTH),
'speed': base_speed * random_factor,
'distance': 0,
'finished': False,
'finish_time': 0
})
# 게임 상태
game_finished = False
start_time = pygame.time.get_ticks()
# 게임 루프
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit()
sys.exit()
screen.fill(WHITE)
draw_tracks()
# 구슬 이동 및 그리기
all_finished = True
for i, ball in enumerate(balls):
if not ball['finished']:
ball['distance'] += ball['speed']
ball['x'], ball['y'] = calculate_track_position(ball['distance'], i)
if ball['distance'] >= total_track_length:
ball['finished'] = True
ball['finish_time'] = (pygame.time.get_ticks() - start_time) / 1000
all_finished = False
# 구슬 그리기
if BALL_COLORS[i] == 'SQUARE_WHITE':
pygame.draw.rect(screen, BLACK, (int(ball['x'])-ball_radius-1, int(ball['y'])-ball_radius-1,
(ball_radius+1)*2, (ball_radius+1)*2))
pygame.draw.rect(screen, WHITE, (int(ball['x'])-ball_radius, int(ball['y'])-ball_radius,
ball_radius*2, ball_radius*2))
elif BALL_COLORS[i] == 'SQUARE_YELLOW':
pygame.draw.rect(screen, BLACK, (int(ball['x'])-ball_radius-1, int(ball['y'])-ball_radius-1,
(ball_radius+1)*2, (ball_radius+1)*2))
pygame.draw.rect(screen, YELLOW, (int(ball['x'])-ball_radius, int(ball['y'])-ball_radius,
ball_radius*2, ball_radius*2))
else:
pygame.draw.circle(screen, BLACK, (int(ball['x']), int(ball['y'])), ball_radius + 1)
pygame.draw.circle(screen, BALL_COLORS[i], (int(ball['x']), int(ball['y'])), ball_radius)
if all_finished and not game_finished:
game_finished = True
print("\n경주 결과:")
sorted_balls = sorted(balls, key=lambda x: x['finish_time'])
for i, ball in enumerate(sorted_balls):
print(f"{i+1}등: {ball['finish_time']:.2f}초")
pygame.display.flip()
clock.tick(60)
* AI 없었으면 한달간은 고생하며 짰어야....
근데 프로그래밍이 말로만 한다고
결코 쉬운게 아니다. ㅎ