gpt4 book ai didi

python - pygame旋转一条线

转载 作者:行者123 更新时间:2023-11-28 20:47:44 25 4
gpt4 key购买 nike

我正在尝试在 Pygame 中创建一个“雷达”。我在旋转雷达指针时遇到问题。如何旋转它?

import pygame
from pygame.locals import *
SIZE = 800, 800
pygame.init()
screen = pygame.display.set_mode(SIZE)
FPSCLOCK = pygame.time.Clock()
done = False
screen.fill((0, 0, 0))
degree=0
while not done:
for e in pygame.event.get():
if e.type == QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
done = True
break
for x in range(1,400,10):
pygame.draw.circle(screen,(255,255,255),(400,400),x,1)
line = pygame.draw.line(screen,(10,100,10),(400,400),(400,0),3)
pygame.transform.rotate(line,degree)
pygame.display.flip()
degree+=5
FPSCLOCK.tick(40)

最佳答案

您需要计算您的开始位置和结束位置。

import math
import pygame
from pygame.locals import *

radar = (100,100)
radar_len = 50
x = radar[0] + math.cos(math.radians(angle)) * radar_len
y = radar[1] + math.sin(math.radians(angle)) * radar_len

# then render the line radar->(x,y)
pygame.draw.line(screen, Color("black"), radar, (x,y), 1)

关于python - pygame旋转一条线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18179877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com