728x90
반응형
#포그슨 방정식
import pygame, sys, math, time #추가명령어 불러오기
pygame.init() #파이게임 모듈 리셋
screen = pygame.display.set_mode((1280, 800)) #화면 설정 가로X세로
pygame.display.set_caption("Pogson's Formula Simulator") #창 이름
font = pygame.font.Font(None,20) #글씨체 생성
class Star:
def __init__(self, absol): #기본정보 입력
self.absol = absol # 절대등급 할당
self.x = 70 #초기 위치
def cal(self):
app = self.absol+(5*math.log10((self.x-40)*1/60))-5 # 포그슨방정식으로 거리에 따른 겉보기 등급 계산
self.app = app #계산값 할당
def move(self): # 움직임 명령어
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
self.x = self.x + 6 # 10pc(거리단위)을 600픽셀로 잡았기에 6픽셀씩 이동
if event.key == pygame.K_LEFT:
self.x = self.x - 6
def display(self): #문자 띄우기 문법 (문자열, True, (색정보), (위치))
screen.blit(font.render("Absolute Magnitude:",True,(0,255,0)),(40,500))
screen.blit(font.render("Apparent Magnitude:",True,(0,255,0)),(40,520))
screen.blit(font.render("Distance(pc):",True,(0,255,0)),(40,540))
screen.blit(font.render(str(self.absol),True,(255,255,255)),(175,500))
screen.blit(font.render(str(self.app),True,(255,255,255)),(175,520))
screen.blit(font.render(str((self.x-40)*1/60),True,(255,255,255)),(125,540))
#마지막 줄 - 60픽셀이 1pc이기 때문에 60으로 나눔
star = Star(5) # 클래스에 대한 개채 생성
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill((0, 0, 0))
star.move()
star.cal()
star.display()
pygame.draw.circle(screen, (0,190,125), (40, 400), 600, 2)
pygame.draw.circle(screen, (0,0,255), (40, 400), 7)
pygame.draw.circle(screen, (255-0.3*(star.x-40),0,0), (star.x, 400), (20))
#멀어질수록 밝기가 낮아지기 때문에 희미해지게
time.sleep(0.1)
pygame.display.update()728x90
반응형
'프로그램' 카테고리의 다른 글
| [파이썬] 문제 : 이중 for 문으로 마지막 문자만 출력하기 (0) | 2022.11.23 |
|---|---|
| [파이썬] 문제 : 사용자 ID/PW 입력 받아 로그인 하기 (0) | 2022.11.23 |
| [파이썬] 문제 : pygame 행성 타원운동 시뮬레이션 코드 분석 (0) | 2022.11.23 |
| [파이썬] 문제 : DataFrame 날짜와 시간까지 리스트로 변환하여 출력 (0) | 2022.11.23 |
| [파이선] 문제 : 파일을 읽어 합계,평균 계산해 다른 파일로 저장하기 (0) | 2022.11.23 |
댓글