forked from uniquekarki/Computer-Graphics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mid_point_circle_algo.py
64 lines (51 loc) · 1.57 KB
/
mid_point_circle_algo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pygame, sys
from pygame.locals import *
from pygame import gfxdraw
pygame.init()
size = (700,700)
screen_surface = pygame.display.set_mode(size, 0, 32)
pygame.display.set_caption("Mid-Point Circle Drawing Algorithm")
BLACK = (0,0,0)
WHITE = (255,255,255)
RED = (255,0,0)
GREEN = (0,128,0)
BLUE = (0,0,255)
screen_surface.fill(WHITE)
def mid_point_circle(radius, xc , yc):
x0,y0 = 0, radius
print("Radius of circle: {}".format(radius))
gfxdraw.pixel(screen_surface, x0,y0, BLACK)
#initial decision parameter
if type(radius) == float:
p0 = (5/4) - radius
else:
p0 = 1 - radius
pk = p0
x, y = x0, y0
while x < y:
if pk < 0:
x, y = x + 1, y
pk = pk + 2 * x + 1
gfxdraw.pixel(screen_surface, x + xc, y + yc, BLACK)
plot_other_points(x,y,xc,yc)
else:
x, y = x + 1, y - 1
pk = pk + 2 * x - 2 * y + 1
gfxdraw.pixel(screen_surface, x + xc, y + yc, BLACK)
plot_other_points(x, y, xc, yc)
# print("Center : {}".format(x, y))
def plot_other_points(x,y,xc,yc):
gfxdraw.pixel(screen_surface,x + xc, -y+xc, BLACK)
gfxdraw.pixel(screen_surface, -x + xc, y + yc, BLACK)
gfxdraw.pixel(screen_surface, -x + xc, -y + yc, BLACK)
gfxdraw.pixel(screen_surface, y + xc, x + yc, BLACK)
gfxdraw.pixel(screen_surface, y + xc, -x + yc, BLACK)
gfxdraw.pixel(screen_surface, -y + xc, -x + yc, BLACK)
gfxdraw.pixel(screen_surface, -y + xc, x + yc, BLACK)
mid_point_circle(100,200,200)
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()