Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##NOTE:
- # CoordList is a list containing, for each pixel, a list containing the RBG value, the position (X,Y), and signifier for 'hit/unhit'
- # ie. [[RGB],[X,Y],0]
- #The function should be outputting a list containing lists containing all the pixels in a contiguous area.
- def FindContiguous(CoordList):
- Shapes = []
- InShapes = []
- UnHit = [CoordList[0]]
- for BPixel in CoordList:
- if BPixel in UnHit and not BPixel in InShapes:
- NewShape = []
- for Pixel in CoordList:
- Pixel[2] == 0
- BPixel[2] = 1
- for Pixel in CoordList:
- if Pixel[2] == 1 and Pixel in UnHit:
- NewShape.append(Pixel)
- InShapes.append(Pixel)
- AdjacentPixels = []
- Up = (Pixel[1][0],Pixel[1][1]+1)
- Down = (Pixel[1][0],Pixel[1][1]-1)
- Left = (Pixel[1][0]+1,Pixel[1][1])
- Right = (Pixel[1][0]-1,Pixel[1][1])
- AdjacentPixels.append(FetchPixel(CoordList,Up))
- AdjacentPixels.append(FetchPixel(CoordList,Down))
- AdjacentPixels.append(FetchPixel(CoordList,Left))
- AdjacentPixels.append(FetchPixel(CoordList,Right))
- for NPixel in AdjacentPixels:
- if NPixel:
- if NPixel[0] == BPixel[0]:
- NPixel[2] = 1
- if Pixel in UnHit:
- In = UnHit.index(Pixel)
- UnHit.remove(Pixel)
- else:
- UnHit.append(Pixel)
- Shapes.append(NewShape)
- return Shapes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement