我不知道這將解決這個問題的任何pygame的功能,這意味着你基本上要編寫自己的解決方案(或使用比pygame的其他東西),因爲draw
壞了你」已經注意到並且gfxdraw
不會給你厚度。
其中一個非常難看但簡單的解決方案是在弧段上多次繪製,總是稍微移動以「填充」缺失的空隙。這仍然會留下一些混淆在計時器弧的很靠前,但其餘的將被填滿。
import pygame
from pygame.locals import *
import pygame.gfxdraw
import math
# Screen size
SCREEN_HEIGHT = 350
SCREEN_WIDTH = 500
# Colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREY = (150, 150, 150)
RED = (255,0,0)
# initialisation
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
done = False
clock = pygame.time.Clock()
# We need this if we want to be able to specify our
# arc in degrees instead of radians
def degreesToRadians(deg):
return deg/180.0 * math.pi
# Draw an arc that is a portion of a circle.
# We pass in screen and color,
# followed by a tuple (x,y) that is the center of the circle, and the radius.
# Next comes the start and ending angle on the "unit circle" (0 to 360)
# of the circle we want to draw, and finally the thickness in pixels
def drawCircleArc(screen,color,center,radius,startDeg,endDeg,thickness):
(x,y) = center
rect = (x-radius,y-radius,radius*2,radius*2)
startRad = degreesToRadians(startDeg)
endRad = degreesToRadians(endDeg)
pygame.draw.arc(screen,color,rect,startRad,endRad,thickness)
# fill screen with background
screen.fill(WHITE)
center = [150, 200]
pygame.gfxdraw.aacircle(screen, center[0], center[1], 105, BLACK)
pygame.gfxdraw.aacircle(screen, center[0], center[1], 120, BLACK)
pygame.display.update()
step = 10
maxdeg = 0
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
maxdeg = maxdeg + step
for i in range(min(0,maxdeg-30),maxdeg):
drawCircleArc(screen,RED,(150,200),119,i+90,max(i+10,maxdeg)+90,14)
#+90 will shift it from starting at the right to starting (roughly) at the top
pygame.display.flip()
clock.tick(2) # ensures a maximum of 60 frames per second
pygame.quit()
注意,我從https://www.cs.ucsb.edu/~pconrad/cs5nm/08F/ex/ex09/drawCircleArcExample.py
複製degreesToRadians
和drawCircleArc
我一般不推薦這種解決方案,但它可能會在一個捏。
看起來更好,但仍然不完美。我會嘗試谷歌或考慮其他可能的解決方案 –
Easiert的方式,如果你需要使用pygame將只是在圖形程序中做,並從spritesheet blit計數器的步驟。如果你只需要在少數幾個地方,手寫黑客可能不值得。 – Isa
爲什麼不繪製下一個段,然後應用洪水填充? –