Skip to content

Instantly share code, notes, and snippets.

@chris-pws
Last active April 25, 2018 21:23
Show Gist options
  • Save chris-pws/4b654494b394b6dd20365522ba105718 to your computer and use it in GitHub Desktop.
Save chris-pws/4b654494b394b6dd20365522ba105718 to your computer and use it in GitHub Desktop.
class Frame():
def __init__( self, width, factor ):
self.width = width
self.factor = factor
def xy_to_index( self, x, y ):
row_offset = ( y << self.factor )
# two pixels per byte; index origin = 0
index = ( row_offset - self.width ) + ( x >> 1 ) + ( x & 1 ) - 1
if ( index < 0 ): index = 0
return index
frame = Frame( 4, 2 )
print ( frame.xy_to_index( 8,1 ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment