-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbressenham_and midpoint_circle_drawing.py
101 lines (85 loc) · 2.32 KB
/
bressenham_and midpoint_circle_drawing.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from graphics import *
import time
window_w = 800
window_h = 800
def eightWaySymmetricPlot(xc,yc,x,y,win):
PutPixle(win,x+xc,y+yc)
PutPixle(win,x+xc,-y+yc)
PutPixle(win,-x+xc,-y+yc)
PutPixle(win,-x+xc,y+yc)
PutPixle(win,y+xc,x+yc)
PutPixle(win,y+xc,-x+yc)
PutPixle(win,-y+xc,-x+yc)
PutPixle(win,-y+xc,x+yc)
def drawAxis(win):
for i in range(window_h):
pt = Point(window_w/2,i)
pt.draw(win)
for i in range(window_w):
pt = Point(i,window_h/2)
pt.draw(win)
def convertPixel(xx,yy):
xx+=window_w/2
yy = -yy
yy+=window_h/2
return xx,yy
def bressenhamCircle(xc,yc,r):
x = 0
y=r
d = 3-(2*r)
win = GraphWin('Midpoint Circle drawing Algorithm', window_w, window_h)
drawAxis(win)
PutPixle(win,xc,yc)
eightWaySymmetricPlot(xc,yc,x,y,win)
while x<=y:
if d<0:
d = d+(4*x)+6
else:
d = d+(4*x)-(4*y)+10
y-=1
x+=1
eightWaySymmetricPlot(xc,yc,x,y,win)
win.getMouse()
win.close()
def midPointCircle(xc,yc,r):
x = 0
y=r
d = 5/float(4)-r
win = GraphWin('Midpoint Circle drawing Algorithm', window_w, window_h)
drawAxis(win)
PutPixle(win,xc,yc)
eightWaySymmetricPlot(xc,yc,x,y,win)
while x<=y:
if d<0:
d =d+2*x+1
else:
d = d+2*(x-y)+1
y-=1
x+=1
eightWaySymmetricPlot(xc,yc,x,y,win)
win.getMouse()
win.close()
def PutPixle(win, x, y):
""" Plot A Pixle In The Windows At Point (x, y) """
newx, newy = convertPixel(x,y)
print("Converted x and y",newx , newy)
pt = Point(newx,newy)
# pt.setFill(color_rgb(50,50,250))
pt.draw(win)
def PutPixle(win, x, y):
""" Plot A Pixle In The Windows At Point (x, y) """
newx, newy = convertPixel(x,y)
print("Converted x and y",newx , newy)
pt = Point(newx,newy)
pt.draw(win)
def main():
xc = int(input("Enter center X: "))
yc = int(input("Enter center Y: "))
r = int(input("Enter Radious r: "))
option = int(input("Enter 1 for Bressenham Circle Algorithm and Enter 2 for Midpoint circle drawing algorithm\n"))
if option==1:
bressenhamCircle(xc,yc,r)
elif option==2:
midPointCircle(xc,yc,r)
if __name__ == "__main__":
main()