I tried something similar with changing the image to a numpy pixel array and the checking the touched pixel and its surroundings. Unfortunately this turned out to not work that great, since it didn't paint all the surrounding pixels, especially when it searched a large area. When I try Image.getpixel I get the error "'module' object has no attribute 'getpixel'.
Any ideas how else I might accomplish this?
Here is the code of my attempt with the numpy array:
def touch_began(self,touch):
self.x1, self.y1 = touch.location
x = int(self.x1)
y = int(self.y1)
x = x * 2
y = y * 2
if pix[y,x] < 255:
self.drawDot(touch.location,self.dotSize)
self.check_area(touch.location, 15)
return
def check_area(self, t, size): # Checks area around touch for dark pixels and paints them red
self.x1, self.y1 = t
x = int(self.x1)
y = int(self.y1)
x = x * 2
y = y * 2
ptsx = []
ptsy = []
thresh = 120
for xx in range(size):
print('x: '+str(xx))
for yy in range(size):
print('y: '+str(yy))
xn = 0
yn = 0
if pix[y + yy, x + xx] < thresh:
xn = (x + xx) * 0.5
yn = (y + yy) * 0.5
# print(xn)
xn = math.ceil(xn)
# print(xn)
yn = math.ceil(yn)
ptsx.append(xn)
ptsy.append(yn)
if pix[y - yy, x - xx] < thresh:
xn = (x - xx) * 0.5
yn = (y - yy) * 0.5
xn = math.ceil(xn)
yn = math.ceil(yn)
ptsx.append(xn)
ptsy.append(yn)
if pix[y + yy, x - xx] < thresh:
xn = (x - xx) * 0.5
yn = (y + yy) * 0.5
xn = math.ceil(xn)
yn = math.ceil(yn)
ptsx.append(xn)
ptsy.append(yn)
if pix[y - yy, x + xx] < thresh:
xn = (x + xx) * 0.5
yn = (y - yy) * 0.5
xn = math.ceil(xn)
yn = math.ceil(yn)
# self.drawDotCoords(xn,yn,self.dotSize)
ptsx.append(xn)
ptsy.append(yn)
# if xn != 0:
# ptsx.append(xn)
# ptsy.append(yn)
if len(ptsx) > 0:
self.drawDotCoords(ptsx,ptsy,self.dotSize) # Draws a one-pixel dot on each surrounding dark pixel