Skip to content

Commit

Permalink
complete distanceTo function of Blob object
Browse files Browse the repository at this point in the history
  • Loading branch information
saadati944 committed Jan 12, 2021
1 parent 9cb4560 commit b0c68ed
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions beadfinder.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import sys
import math
from stdlibrary import picture, color


class Blob:
pixels = []
def __init__(self):
'''
create new instance of blob object
'''
self.pixels = []

def add(self, x, y):
'''
Expand All @@ -19,7 +24,14 @@ def mass(self):
return len(self.pixels)

def distanceTo(self, c):
pass
'''
calculate distance to another Blob
formula :
d = radical( (x2-x1)^2 + (y2-y1)^2)
'''
center1 = self.center()
center2 = c.center()
return math.sqrt((center2[0]-center1[0])**2 + (center2[1] - center1[1])**2)

def center(self):
'''
Expand Down

0 comments on commit b0c68ed

Please sign in to comment.