Basic formula for a circle
(x - a)**2 + (y - b)**2 = r**2
Where (x, y) is the point, (a, b) is the center of the circle, and r is the radius.
width, height = 11, 11 a, b = 5, 5 r = 5 EPSILON = 2.2 map_ = [['.' for x in range(width)] for y in range(height)] # draw the circle for y in range(height): for x in range(width): # see if we're close to (xa)**2 + (yb)**2 == r**2 if abs((xa)**2 + (yb)**2 - r**2) < EPSILON**2: map_[y][x] = '#' # print the map for line in map_: print ' '.join(line)
The result is
. . .
With this method you will have to play with the value of EPSILON .
Alternatively, iterate over the angle and calculate the coordinate (x, y) along the way
import math # draw the circle for angle in range(0, 360, 5): x = r * math.sin(math.radians(angle)) + a y = r * math.cos(math.radians(angle)) + b map_[int(round(y))][int(round(x))] = '#'
gives:
. . .
source share