import math
import pygame
def init_game():
pygame.init()
pygame.key.set_repeat(0)
canvas = pygame.display.set_mode((800, 600))
fps_clock = pygame.time.Clock()
return canvas, fps_clock
def main():
canvas, fps_clock = init_game()
title = 'Cardioid'
pygame.display.set_caption(title)
max_dots = 300
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
return
draw_cardioid(canvas, max_dots)
pygame.display.update()
fps_clock.tick(30)
def draw_cardioid(canvas, max_dots):
canvas.fill((0, 0, 0))
start_x = canvas.get_width() // 2
start_y = canvas.get_height() // 2
radius = 250
for i in range(max_dots):
radian = (math.pi / 180) * (360 / max_dots) * i
sx = start_x + int(math.cos(radian) * radius)
sy = start_y + int(math.sin(radian) * radius)
ex = start_x + int(math.cos(radian * 2) * radius)
ey = start_y + int(math.sin(radian * 2) * radius)
pygame.draw.line(canvas, (0, 255, 0), (sx, sy), (ex, ey))
if __name__ == '__main__':
main()
'Coding > Python 삽질기' 카테고리의 다른 글
[SQL] BEGIN TRANSACTION (0) | 2024.03.07 |
---|---|
[Python] PNG to ICO 변환 하기 (0) | 2024.01.04 |
[Python] 프랙탈 나무 만들기 (0) | 2023.09.15 |