-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bresenam.py
66 lines (52 loc) · 1.15 KB
/
Bresenam.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
print("Welcome in python")
from graphics import *
print("Enter the Radius of a circle : ")
r = int(input())
p = 3 - 2*r
# center of circle:
xn = yn = 150
x1 = 0
y1 = r
win = GraphWin("Bresenham-circle-draw",500, 500)
plt = Point(xn+x1,yn+y1)
plt.draw(win)
plt = Point(xn+y1,yn+x1)
plt.draw(win)
plt = Point(xn+x1,yn-y1)
plt.draw(win)
plt = Point(xn+y1,yn-x1)
plt.draw(win)
plt = Point(xn-x1,yn-y1)
plt.draw(win)
plt = Point(xn-x1,yn+y1)
plt.draw(win)
plt = Point(xn-y1,yn+x1)
plt.draw(win)
plt = Point(xn-y1,yn-x1)
plt.draw(win)
while x1 < y1 :
if p < 0 :
p = p + 4*x1 + 6
else :
y1 = y1 - 1
p = p + 4*(x1-y1) + 10
x1 = x1+1
if x1 < y1 :
plt = Point(xn+x1,yn+y1)
plt.draw(win)
plt = Point(xn+y1,yn+x1)
plt.draw(win)
plt = Point(xn+x1,yn-y1)
plt.draw(win)
plt = Point(xn+y1,yn-x1)
plt.draw(win)
plt = Point(xn-x1,yn-y1)
plt.draw(win)
plt = Point(xn-x1,yn+y1)
plt.draw(win)
plt = Point(xn-y1,yn+x1)
plt.draw(win)
plt = Point(xn-y1,yn-x1)
plt.draw(win)
# Enter to exit:
x = int(input())