Skip to content

Instantly share code, notes, and snippets.

@astkaasa
Last active December 16, 2015 06:39
Show Gist options
  • Save astkaasa/5392911 to your computer and use it in GitHub Desktop.
Save astkaasa/5392911 to your computer and use it in GitHub Desktop.
problem 5.8
//assume x1 < x2
drawHorizontalLine( byte[] screen, int width, int x1, int x2, int y ) {
int start = y * width / 8 + ( int ) x1 / 8;
int end = y * width / 8 + ( int ) x2 / 8;
for ( int i = start; i <= end; i++ ) {
screen[ i ] = 127;
}
if ( start == end ) {
screen[ start ] = screen[ start ] >> ( x1 % 8 );
byte mask = 127 << ( 8 - x2 % 8 );
screen[ start ] = screen[ start ] ^ mask;
}
else {
screen[ start ] = screen[ start ] >> ( x1 % 8 );
screen[ end ] = screen[ end ] << ( 8 - x2 % 8 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment