简体   繁体   English

Python-Pygame-圆周运动

[英]Python - Pygame - circular movement

I´ve the following code: 我有以下代码:

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()

this creates me a circle, which circles around the coordination (0, 0). 这将创建一个圆圈,该圆圈围绕坐标(0,0)旋转。
i want to move the center from (0, 0) to (100, 100). 我想将中心从(0,0)移至(100,100)。

Thank you in advance 先感谢您

Just add 100 to the x and y coordinates to adjust the center position: 只需在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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM