BRESENHAMS CIRCLE
unknown
python
2 years ago
788 B
27
Indexable
import matplotlib.pyplot as plt def draw_circle(h, k, r): x = r y = 0 P = 1 - r points = [] while x >= y: points.extend([(x + h, y + k), (y + h, x + k), (-x + h, y + k), (-y + h, x + k), (-x + h, -y + k), (-y + h, -x + k), (x + h, -y + k), (y + h, -x + k)]) y += 1 if P <= 0: P = P + 2 * y + 1 else: x -= 1 P = P + 2 * y - 2 * x + 1 return points # Example usage: circle_points = draw_circle(5, 5, 4) # Plotting x_vals, y_vals = zip(*circle_points) plt.plot(x_vals, y_vals, marker='o', linestyle='', markersize=3) plt.title('Bresenham\'s Circle Drawing Algorithm') plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.grid(True) plt.show()
Editor is loading...
Leave a Comment