我试图让弧跟随我的鼠标,而停留在圆的路径
我不知道为什么它不起作用
当我运行它时,它只创建一个pygame白色屏幕,没有任何错误
这是我的密码:
from __future__ import division
from math import atan2, degrees, pi
import math
import pygame
pygame.init()
screen = pygame.display.set_mode((800, 800))
pygame.display.set_caption("globe")
CENTER = (400, 400)
RADIUS = 350
running = True
def drawCircleArc(screen,color,center,radius,startDeg,endDeg,thickness):
(x,y) = center
rect = (x-radius,y-radius,radius*2,radius*2)
startRad = math.radians(startDeg)
endRad = math.radians(endDeg)
pygame.draw.arc(screen,color,rect,startRad,endRad,thickness)
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
mouse = pygame.mouse.get_pos()
relx = mouse[0] - CENTER[0]
rely = mouse[1] - CENTER[1]
rad = atan2(-rely,relx)
rad %= 2*pi
degs = degrees(rad)
screen.fill((152,206,231))
drawCircleArc(screen,(243,79,79),CENTER,RADIUS, degs + 90,degs + 100 ,10)
pygame.draw.circle(screen, (71,153,192), CENTER, RADIUS)
pygame.display.update()
pygame.quit()
我真正想要的是下图 谢谢
我想下面的就可以了。我解决了两个问题:
您按错误的顺序绘制图形,并遮住了红色的短弧(需要从后向前绘制),并且
添加到计算的
degs
角度的两个文字值太大我还做了其他一些不太需要的更改,包括按照PEP 8 - Style Guide for Python Code准则重新格式化代码,并添加
pygame.time.Clock
以降低刷新速度,使之达到我认为更合理的程度下面是跑步的样子
相关问题 更多 >
编程相关推荐