我有这个代码的问题,因为我想要4个点(圆圈)来制作正方形的顶点,但我不知道区别应该是什么在这些顶点之间(变量“变化”)。我把这个变量留空了,请你给我值,我应该插入并解释为什么?Python - Pygame:“坐标上的正方形的坐标”
下面的代码:
import pygame
from math import sin, cos
pygame.init()
screen = pygame.display.set_mode((800,600))
BLACK = (0,0,0)
WHITE = (255,255,255)
BLUE = (0,0,255)
GRAY = (175,175,175)
clock = pygame.time.Clock()
Font = pygame.font.SysFont(None, 50)
angle = 0
angle_c = 0
ex = False
a = (0,0)
b = (0,0)
c = (0,0)
d = (0,0)
change =
size = 95
x_c = 400
y_c = 200
while not ex:
for event in pygame.event.get():
if event.type == pygame.QUIT:
ex = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
angle_c = 0.05
if event.key == pygame.K_RIGHT:
angle_c = -0.05
if event.type == pygame.KEYUP:
if event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT:
angle_c = 0
angle += angle_c
a = (round(sin(angle)*size+x_c), round(cos(angle)*size+y_c))
b = (round(sin(angle+change)*size+x_c), round(cos(angle+change)*size+y_c))
c = (round(sin(angle+change*2)*size+x_c), round(cos(angle+change*2)*size+y_c))
d = (round(sin(angle+change*3)*size+x_c), round(cos(angle+change*3)*size+y_c))
screen.fill(WHITE)
pygame.draw.circle(screen, BLUE, (400,200), round(sin(360)*100), 3)
pygame.draw.circle(screen, BLUE, a, 10)
pygame.draw.circle(screen, WHITE, a, 8)
pygame.draw.circle(screen, BLUE, b, 10)
pygame.draw.circle(screen, WHITE, b, 8)
pygame.draw.circle(screen, BLUE, c, 10)
pygame.draw.circle(screen, WHITE, c, 8)
pygame.draw.circle(screen, BLUE, d, 10)
pygame.draw.circle(screen, WHITE, d, 8)
pygame.display.update()
clock.tick(50)
pygame.quit()
欢迎来到StackOverflow。请阅读并遵守帮助文档中的发布准则。 [最小,完整,可验证的示例](http://stackoverflow.com/help/mcve)适用于此处。在发布您的MCVE代码并准确描述问题之前,我们无法为您提供有效的帮助。 具体来说,展示你的最佳尝试和不正确的输出。 – Prune