Advertisement
zfoxatis

python27 fill

Feb 4th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. ''' egy kis fill '''
  2.  
  3.     def fill(self,x,y):
  4.         startcolor=self.kep.getpixel((x,y))
  5.         fillcolor=(255,0,0)
  6.         fillbuffer={}
  7.         fillbuffer[(x,y)]=''
  8.         while len(fillbuffer):
  9.             currentpixel=fillbuffer.popitem()[0]
  10.             for i,j in [(0,1),(0,-1),(1,0),(-1,0)]:
  11.                 nezpixel=currentpixel[0]+i,currentpixel[1]+j
  12.                 if self.kep.getpixel(nezpixel)==startcolor and 0<nezpixel[0]<249 and 0<nezpixel[1]<249:
  13.                     self.rajzol.point(nezpixel,fillcolor)
  14.                     if  nezpixel not in fillbuffer: #nem tudom hogy igazából kell-e ez ide logikailag igen de amugy csak lassít...
  15.                         fillbuffer[nezpixel]=''
  16.                         maxlen=max(maxlen,len(fillbuffer))
  17.         self.vaszonkep.paste(self.kep)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement