Skip to content

Instantly share code, notes, and snippets.

@jyhjuzi
Created July 29, 2014 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jyhjuzi/9588ff61cd446a9761a3 to your computer and use it in GitHub Desktop.
Save jyhjuzi/9588ff61cd446a9761a3 to your computer and use it in GitHub Desktop.
package Chapter5;
public class Q5_8{
static void drawHorizontalLine(byte[] screen, int width, int x1, int x2, int y){
int height = screen.length/width/8;
int startOffset = x1%8;
int firstFullByte = x1/8;
if(startOffset!=0)
firstFullByte ++;
int endOffset = x2%8;
int lastFullByte = x2/8;
if(endOffset !=7)
lastFullByte --;
for(int i = firstFullByte; i <= lastFullByte; i++){
screen[y*width/8+i]=(byte) 0xff;
}
byte startMask = (byte) (0xff >> startOffset);
byte endMask = (byte) ~(0xff>>(endOffset+1));
if(x1/8 == x2/8){
byte wholeMask = (byte) (startMask & endMask);
screen[y*width/8+x1/8]|=wholeMask;
}
else if(startOffset!=0){
screen[y*width/8+firstFullByte-1] |= startMask;
}
else if(endOffset!=7)
screen[y*width/8+lastFullByte+1] |= endMask;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment