Pygame, the python game development library, gives the possibility to draw multiple geometrical shapes using its sub module draw: rectangles, polygons, circles, ellipses, lines and arcs… However, the arc drawing function is presenting some bugs and pygame is not showing any signs of fixing it. When drawing an arc, the function seem to generate some gaps in the drawn shape. In this short tutorial, we propose a fast solution to draw Arcs in Pygame without gaps.
Using built-in function (With gaps):
This code below draws an Arc between 30° and 160° with a thickness of 40:
################# IMPORTING/INITIALIZING LIBRARIES
import pygame, pygame.gfxdraw
import sys, numpy, math
mainClock = pygame.time.Clock()
from pygame.locals import *
pygame.init()
################# SCREEN SETTING
pygame.display.set_caption('Arc tutorial')
screen = pygame.display.set_mode((500,500), pygame.RESIZABLE)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.draw.arc(screen,(50,50,255),pygame.Rect(0,0,500,500),30*math.pi/180,160*math.pi/180,width=40)
pygame.display.update()
mainClock.tick(60)

As we can see in the resulting image, the shape seems to have some gaps. This is due to the fact that the function draws with a thickness of 40, as 40 arcs with a thickness of 1. This phenomenon is also called aliasing.
To solve this we propose the custom function below:
Using custom function (Without gaps):
This function uses the filled_polygon function to draw the arc, it creates the points enveloping the arc then fills it with the passed color.
def draw_arc(surface, x, y, r, th, start, stop, color):
points_outer = []
points_inner = []
n = 300
for i in range(n):
delta = i/n
phi = (start + (stop-start)*delta)*math.pi/180
x0 = round(x+r*math.cos(phi))
y0 = round(y+r*math.sin(phi))
points_outer.append([x0,y0])
x1 = round(x+(r-th)*math.cos(phi))
y1 = round(y+(r-th)*math.sin(phi))
points_inner.append([x1,y1])
points = numpy.append(points_inner , numpy.flip(points_outer,0), axis=0)
pygame.gfxdraw.filled_polygon(surface, points, color)
We use this function in the context of a simple game:
################# IMPORTING/INITIALIZING LIBRARIES
import pygame, pygame.gfxdraw
import sys, numpy, math
mainClock = pygame.time.Clock()
from pygame.locals import *
pygame.init()
################# SCREEN SETTING
pygame.display.set_caption('Arc tutorial')
screen = pygame.display.set_mode((500,500), pygame.RESIZABLE)
################# FUNCTION
def draw_arc(surface, x, y, r, th, start, stop, color):
points_outer = []
points_inner = []
n = 300
for i in range(n):
delta = i/n
phi = math.pi/180 - (start + (stop-start)*delta)*math.pi/180
x0 = round(x+r*math.cos(phi))
y0 = round(y+r*math.sin(phi))
points_outer.append([x0,y0])
x1 = round(x+(r-th)*math.cos(phi))
y1 = round(y+(r-th)*math.sin(phi))
points_inner.append([x1,y1])
points = numpy.append(points_inner , numpy.flip(points_outer,0), axis=0)
pygame.gfxdraw.filled_polygon(surface, points, color)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
draw_arc(screen, 250, 250, 250, 40, 30, 160, (50,50,255))
pygame.display.update()
mainClock.tick(60)
The implemented function gives up the possibility to draw an arc without gaps:
