Last active
December 16, 2015 06:39
-
-
Save astkaasa/5392911 to your computer and use it in GitHub Desktop.
problem 5.8
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
//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