Last active
April 25, 2018 21:23
-
-
Save chris-pws/4b654494b394b6dd20365522ba105718 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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