Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def getCoordPixel(pixels, width, height, index, x=0, y=0):
- bx = (index % width) + x
- by = (index // height) + y
- ex = -1 < bx < width and -1 < by < height
- indexB = index + x + (y * width) if ex else None
- pixelB = pixels[indexB] if indexB else None
- return pixelB
- index = 8
- width = 4
- height = 4
- pixels = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
- print '[ \][x0][x1][x2][x3]'
- print '[y0] 0, 1, 2, 3'
- print '[y1] 4, 5, 6, 7'
- print '[y2] 8, 9, 10, 11'
- print '[y3] 12, 13, 14, 15'
- print ''
- print 'index:', index
- print 'R=Right, B=Bottom, L=Left, T=Top'
- print ' R:', getCoordPixel(pixels, width, height, index, x= 1, y= 0) # 9
- print ' B:', getCoordPixel(pixels, width, height, index, x= 0, y= 1) # 12
- print ' L:', getCoordPixel(pixels, width, height, index, x=-1, y= 0) # None
- print ' T:', getCoordPixel(pixels, width, height, index, x= 0, y=-1) # 4
- print ' TR:', getCoordPixel(pixels, width, height, index, x= 1, y=-1) # 5
- print ' BR:', getCoordPixel(pixels, width, height, index, x= 1, y= 1) # 13
- print ' BL:', getCoordPixel(pixels, width, height, index, x=-1, y= 1) # None
- print ' TL:', getCoordPixel(pixels, width, height, index, x=-1, y=-1) # None
- print ' RR:', getCoordPixel(pixels, width, height, index, x= 2, y= 0) # 10
- print ' BB:', getCoordPixel(pixels, width, height, index, x= 0, y= 2) # None
- print ' LL:', getCoordPixel(pixels, width, height, index, x=-2, y= 0) # None
- print ' TT:', getCoordPixel(pixels, width, height, index, x= 0, y=-2) # 0
- print 'TTRR:', getCoordPixel(pixels, width, height, index, x= 2, y=-2) # 2
- print 'BBRR:', getCoordPixel(pixels, width, height, index, x= 2, y= 2) # None
- print 'BBLL:', getCoordPixel(pixels, width, height, index, x=-2, y= 2) # None
- print 'TTLL:', getCoordPixel(pixels, width, height, index, x=-2, y=-2) # None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement