我正在尝试绘制一条以与时钟指针相同的方式移动的线,但是当我运行程序时,线移动了 20 度,然后程序被冻结,我可以读到:“ValueError:数学域错误”
这里是我写的代码:
import pygame
import sys
import time
import math
from pygame.locals import *
pygame.init()
windowSurface = pygame.display.set_mode((300, 600), 0, 32)
pygame.display.set_caption("circle_line")
BLACK = (0, 0, 0)
WHITE = (250, 250, 250)
R = 50
CIRCLE_LINE_START_X = 150
CIRCLE_LINE_START_Y = 300
CIRCLE_LINE_END_X = CIRCLE_LINE_START_X
CIRCLE_LINE_END_Y = CIRCLE_LINE_START_Y - R
MOVE_SPEED = 3
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if CIRCLE_LINE_END_X <= CIRCLE_LINE_START_X and CIRCLE_LINE_END_Y <= CIRCLE_LINE_START_Y :
CIRCLE_LINE_END_X -= MOVE_SPEED
CIRCLE_LINE_END_Y = math.sqrt(R**2 - ((CIRCLE_LINE_END_X - CIRCLE_LINE_START_X)**2)) + CIRCLE_LINE_START_Y
if CIRCLE_LINE_END_X <= CIRCLE_LINE_START_X and CIRCLE_LINE_END_Y >= CIRCLE_LINE_START_Y :
CIRCLE_LINE_END_X += MOVE_SPEED
CIRCLE_LINE_END_Y = math.sqrt(R**2 - ((CIRCLE_LINE_END_X - CIRCLE_LINE_START_X)**2)) + CIRCLE_LINE_START_Y
if CIRCLE_LINE_END_X >= CIRCLE_LINE_START_X and CIRCLE_LINE_END_Y >= CIRCLE_LINE_START_Y :
CIRCLE_LINE_END_X += MOVE_SPEED
CIRCLE_LINE_END_Y = math.sqrt(R**2 - ((CIRCLE_LINE_END_X - CIRCLE_LINE_START_X)**2)) + CIRCLE_LINE_START_Y
if CIRCLE_LINE_END_X >= CIRCLE_LINE_START_X and CIRCLE_LINE_END_Y <= CIRCLE_LINE_START_Y :
CIRCLE_LINE_END_X -= MOVE_SPEED
CIRCLE_LINE_END_Y = math.sqrt(R**2 - ((CIRCLE_LINE_END_X - CIRCLE_LINE_START_X)**2)) + CIRCLE_LINE_START_Y
windowSurface.fill(WHITE)
pygame.draw.line(windowSurface, BLACK, (CIRCLE_LINE_START_X, CIRCLE_LINE_START_Y), (CIRCLE_LINE_END_X, CIRCLE_LINE_END_Y), 3)
pygame.display.update()
time.sleep(0.02)
任何帮助找出我的错误将不胜感激。
谢谢你。