I recently figured out how to draw an arc in pygame without moire holes
and allowing stuff like antialiasing. Just if any of your are interested.
The script is a little slow.
Also: atan issues where the arc starts out from the left instead of top.
I can't seem to fix it.
--Rockachu2
import math
def draw_arc_matrix(matrix, pos, radius, color, width, angle1, angle2):
#print "Drawing arc at", pos, "with radius of ", radius
for x in xrange(getmatrixwidth(matrix)):
for y in xrange(getmatrixheight(matrix)):
n = ((x-pos[0])**2 )+ ((y-pos[1])**2 )
if n > (radius-width)**2:
if n < (radius)**2:
## now to check arc
#print x,y
#setpoint(matrix, [x,y], color)
angle = math.atan2(y-pos[1], x-pos[0])
angle = math.degrees(angle)+180
#print angle, angle1, angle2
if angle1 > angle2:
if angle < angle1:
if angle > angle2:
setpoint(matrix, [x,y], color)
#print x,y
else:
if angle > angle1:
if angle < angle2:
#print x,y
setpoint(matrix, [x,y], color)
def setpoint(matrix, pos, color):
matrix.set_at(pos, color)
#matrix[pos[0]][pos[1]] = color
#return matrix
def getmatrixwidth(matrix):
# reurn len(matrix)
return matrix.get_rect().width
def getmatrixheight(matrix):
# return len(matrix[0])
return matrix.get_rect().height
if __name__ == "__main__":
import pygame
pygame.init()
screen = pygame.display.set_mode((200,200))
angle = 0
anglec = 1
while True:
anglec += .1
anglec %= 360
screen.fill((0,0,0))
draw_arc_matrix(screen, (100,100), 80, (255,255,255), 10, angle, anglec)
pygame.display.update()
pygame.event.get()