-
Notifications
You must be signed in to change notification settings - Fork 0
/
04-Mid-point-ellipse.py
66 lines (47 loc) · 1.13 KB
/
04-Mid-point-ellipse.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
# Mid point Ellipse drawing Algorithm
from graphics import *
def putPixel(win, x, y):
pt = Point(x,y)
pt.draw(win)
def midpointEllipse(cx,cy,a,b):
win = GraphWin("Mid point ellipse drawing algorithm", 500, 500)
x=0
y=b
P1= b**2+ (a**2)/4 - a*a*b
while 2*b*b*x<=2*a*a*y:
# print(x,y)
putPixel(win,x+cx,y+cy)
putPixel(win,-x+cx,y+cy)
putPixel(win,-x+cx,-y+cy)
putPixel(win,x+cx,-y+cy)
if P1<0:
x = x+1
P1 = P1+b*b*(2*x+1)
else:
x = x+1
y = y-1
P1 = P1+b*b*(2*x+1)-2*a*a*y
P2= b*b*(x+1/2)**2 + a*a*(y-1)**2 - a*a*b*b
while y>=0:
# print(x,y)
putPixel(win,x+cx,y+cy)
putPixel(win,-x+cx,y+cy)
putPixel(win,-x+cx,-y+cy)
putPixel(win,x+cx,-y+cy)
if P2>=0:
y = y-1
P2 = P2+a*a*(1-2*y)
else:
x = x+1
y = y-1
P2 = P2+a*a*(1-2*y)+2*b*b*x
win.getMouse()
def main():
print("Enter centre of ellipse")
cx = int(input("Enter x: "))
cy = int(input("Enter y: "))
print("\n")
a = int(input("Enter radius along x-axis: "))
b = int(input("Enter radius along y-axis: "))
midpointEllipse(cx,cy,a,b)
main()