-
Notifications
You must be signed in to change notification settings - Fork 0
/
midpoint circle.py
46 lines (40 loc) · 1.41 KB
/
midpoint circle.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
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
img = Image.fromarray(np.zeros((150, 150), dtype=np.float32), mode= "F")
def midPoint_Circle(x, y, ycenter, xcenter):
p = 1.25 - y
img.putpixel((x+xcenter, y+ycenter), 3)
img.putpixel((-x+xcenter, y+ycenter), 3)
img.putpixel((x+xcenter, -y+ycenter), 3)
img.putpixel((-x+xcenter, -y+ycenter), 3)
if x!=y:
img.putpixel((y+xcenter, x+ycenter), 3)
img.putpixel((-y+xcenter, x+ycenter), 3)
img.putpixel((y+xcenter, -x+ycenter), 3)
img.putpixel((-y+xcenter, -x+ycenter), 3)
while(x<=y):
x = x+1
if(p >= 0):
y -= 1
p = p + 2*x - 2*y + 5
else:
p = p + 2*x + 3
if(x>y):
break
img.putpixel((x+xcenter, y+ycenter), 3)
img.putpixel((-x+xcenter, y+ycenter), 3)
img.putpixel((x+xcenter, -y+ycenter), 3)
img.putpixel((-x+xcenter, -y+ycenter), 3)
if x!=y:
img.putpixel((y+xcenter, x+ycenter), 3)
img.putpixel((-y+xcenter, x+ycenter), 3)
img.putpixel((y+xcenter, -x+ycenter), 3)
img.putpixel((-y+xcenter, -x+ycenter), 3)
midPoint_Circle(0,50,70,70)
midPoint_Circle(0,10,50,90)
midPoint_Circle(0,10,90,90)
midPoint_Circle(0,20,70,50)
img = np.transpose(img)
plt.imshow(np.array(img))
plt.show()