Advertisement
Guest User

Untitled

a guest
May 14th, 2011
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. ##NOTE:
  2. # CoordList is a list containing, for each pixel, a list containing the RBG value, the position (X,Y), and signifier for 'hit/unhit'
  3. # ie. [[RGB],[X,Y],0]
  4. #The function should be outputting a list containing lists containing all the pixels in a contiguous area.
  5.  
  6. def FindContiguous(CoordList):
  7.     Shapes = []
  8.     InShapes = []
  9.     UnHit = [CoordList[0]]
  10.     for BPixel in CoordList:
  11.         if BPixel in UnHit and not BPixel in InShapes:
  12.             NewShape = []
  13.             for Pixel in CoordList:
  14.                 Pixel[2] == 0
  15.             BPixel[2] = 1
  16.             for Pixel in CoordList:
  17.                 if Pixel[2] == 1 and Pixel in UnHit:
  18.                     NewShape.append(Pixel)
  19.                     InShapes.append(Pixel)
  20.                     AdjacentPixels = []
  21.                     Up = (Pixel[1][0],Pixel[1][1]+1)
  22.                     Down = (Pixel[1][0],Pixel[1][1]-1)
  23.                     Left = (Pixel[1][0]+1,Pixel[1][1])
  24.                     Right = (Pixel[1][0]-1,Pixel[1][1])
  25.                     AdjacentPixels.append(FetchPixel(CoordList,Up))
  26.                     AdjacentPixels.append(FetchPixel(CoordList,Down))
  27.                     AdjacentPixels.append(FetchPixel(CoordList,Left))
  28.                     AdjacentPixels.append(FetchPixel(CoordList,Right))
  29.                     for NPixel in AdjacentPixels:
  30.                         if NPixel:
  31.                             if NPixel[0] == BPixel[0]:
  32.                                 NPixel[2] = 1
  33.                     if Pixel in UnHit:
  34.                         In = UnHit.index(Pixel)
  35.                         UnHit.remove(Pixel)
  36.                 else:
  37.                     UnHit.append(Pixel)
  38.             Shapes.append(NewShape)
  39.     return Shapes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement