-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmid point circle.py
More file actions
64 lines (50 loc) · 1.87 KB
/
mid point circle.py
File metadata and controls
64 lines (50 loc) · 1.87 KB
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
from graphics import *
win = GraphWin("Midpoint Circle", 600, 600)
def midPointCircleDraw(x_centre, y_centre, r):
x = r
y = 0
print("(", x + x_centre, ", ", y + y_centre, ")")
if r > 0:
print("({xval}, {yval})".format(xval=x+x_centre, yval=y+y_centre))
print("(", y + x_centre, ", ", x + y_centre, ")")
print("(", -y + x_centre, ", ", x + y_centre, ")")
P = 1 - r
while x > y:
y += 1
if P <= 0:
P = P + 2 * y + 1
else:
x -= 1
P = P + 2 * y - 2 * x + 1
if x < y:
break
print("(", x + x_centre, ", ", y + y_centre, ")")
print("(", -x + x_centre, ", ", y + y_centre, ")")
print("(", x + x_centre, ", ", -y + y_centre, ")")
print("(", -x + x_centre, ", ", -y + y_centre, ")")
plotPoints(x + x_centre, y + y_centre)
plotPoints(-x + x_centre, y + y_centre)
plotPoints(x + x_centre, -y + y_centre)
plotPoints(-x + x_centre, -y + y_centre)
if x != y:
print("(", y + x_centre, ", ", x + y_centre, ")")
print("(", -y + x_centre, ", ", x + y_centre, ")")
print("(", y + x_centre, ", ", -x + y_centre, ")")
print("(", -y + x_centre, ", ", -x + y_centre, ")")
plotPoints(y + x_centre, x + y_centre)
plotPoints(-y + x_centre, x + y_centre)
plotPoints(y + x_centre, -x + y_centre)
plotPoints(-y + x_centre, -x + y_centre)
def getInput():
x = int(input("Enter the x coordinate of the centre: "))
y = int(input("Enter the y coordinate of the centre: "))
r = int(input("Enter the radius of the circle: "))
return x, y, r
def plotPoints(x, y):
point = Point(x, y)
point.draw(win)
if __name__ == '__main__':
xc, yc, rc = getInput()
midPointCircleDraw(xc, yc, rc)
win.getMouse()
win.close()