Python-Pygame-圆周运动

时间:2018-10-19 12:49:44

标签: python pygame

我有以下代码:

import pygame, sys, math

run = True
white = (255, 255, 255)
black = (0, 0, 0)
angle = 0
size = width, height = 800, 800
screen = pygame.display.set_mode(size)

clock = pygame.time.Clock()
screen.fill(white)

while run:
    msElapsed = clock.tick(60)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
    screen.fill(white)
    pygame.draw.circle(screen, black, (int(math.cos(angle) * 100), int(math.sin(angle) * 100)), 10)

    pygame.display.flip()
    angle += 0.05

pygame.quit()

这将为我创建一个圆圈,该圆圈围绕坐标(0,0)旋转。
我想将中心从(0,0)移至(100,100)。

预先谢谢你

1 个答案:

答案 0 :(得分:0)

只需在x和y坐标上加上100即可调整中心位置:

x = int(math.cos(angle) * 100) + 100
y = int(math.sin(angle) * 100) + 100
pygame.draw.circle(screen, black, (x, y), 10)