void OutGraphicsCharFont1(int x, int y, int fontcolour, int backgroundcolour, int c, int Erase) { // using register variables (as opposed to stack based ones) may make execution faster // depends on compiler and CPU register int row, column, theX = x, theY = y ; register int pixels ; register char theColour = fontcolour ; register int BitMask, theC = c ; // if x,y coord off edge of screen don't bother // XRES and YRES are #defined to be 800 and 480 respectively if(((short)(x) > (short)(XRES-1)) || ((short)(y) > (short)(YRES-1))) return ; // if printable character subtract hex 20 if(((short)(theC) >= (short)(' ')) && ((short)(theC) <= (short)('~'))) { theC = theC - 0x20 ; for(row = 0; (char)(row) < (char)(7); row ++) { // get the bit pattern for row 0 of the character from the software font pixels = Font5x7[theC][row] ; BitMask = 16 ; for(column = 0; (char)(column) < (char)(5); column ++) { // if a pixel in the character display it if((pixels & BitMask)) WriteAPixel(theX+column, theY+row, theColour) ; else { if(Erase == 1) // if pixel is part of background (not part of character) // erase the background to value of variable BackGroundColour WriteAPixel(theX+column, theY+row, backgroundcolour) ; } BitMask = BitMask >> 1 ; } } }
void TestLine(int x1, int y1, int x2, int y2, int Colour) { int x = x1; int y = y1; int dx = abs(x2 - x1); int dy = abs(y2 - y1); int s1 = sign(x2 - x1); int s2 = sign(y2 - y1); int i, temp, interchange = 0, error ; // if x1=x2 and y1=y2 then it is a line of zero length if(dx == 0 && dy == 0) return ; // must be a complex line so use bresenhams algorithm else { // swap delta x and delta y depending upon slop of line if(dy > dx) { temp = dx ; dx = dy ; dy = temp ; interchange = 1 ; } // initialise the error term to compensate for non-zero intercept error = (dy << 1) - dx ; // (2 * dy) - dx // main loop for(i = 1; i <= dx; i++) { WriteAPixel(x, y, Colour); while(error >= 0) { if(interchange == 1) x += s1 ; else y += s2 ; error -= (dx << 1) ; // times 2 } if(interchange == 1) y += s2 ; else x += s1 ; error += (dy << 1) ; // times 2 } } }
/* * Draw a circle (one pixel at a time) * Prints an error message and returns without drawing anything if any points would be off screen */ void TestCircle(int x0, int y0, int radius, int color) { if (ASSERT_POINTS_ARE_VALID && !check_if_point_is_on_screen(x0, y0)) { printf("ERROR: DrawCircle failed for center point (%d,%d)\n", x0, y0); return; } if (ASSERT_POINTS_ARE_VALID && !check_if_point_is_on_screen(x0+radius, y0)) { printf("ERROR: DrawCircle failed in positive x direction (%d,%d)\n", x0+radius, y0); return; } if (ASSERT_POINTS_ARE_VALID && !check_if_point_is_on_screen(x0, y0+radius)) { printf("ERROR: DrawCircle failed in positive y direction (%d,%d)\n", x0, y0+radius); return; } if (ASSERT_POINTS_ARE_VALID && !check_if_point_is_on_screen(x0-radius, y0)) { printf("ERROR: DrawCircle failed in negative x direction (%d,%d)\n", x0-radius, y0); return; } if (ASSERT_POINTS_ARE_VALID && !check_if_point_is_on_screen(x0, y0-radius)) { printf("ERROR: DrawCircle failed in negative y direction (%d,%d)\n", x0, y0-radius); return; } int x = radius; int y = 0; int decisionOver2 = 1 - x; // Decision criterion divided by 2 evaluated at x=r, y=0 while( y <= x ) { WriteAPixel( x + x0, y + y0, color); // Octant 1 WriteAPixel( y + x0, x + y0, color); // Octant 2 WriteAPixel(-x + x0, y + y0, color); // Octant 4 WriteAPixel(-y + x0, x + y0, color); // Octant 3 WriteAPixel(-x + x0, -y + y0, color); // Octant 5 WriteAPixel(-y + x0, -x + y0, color); // Octant 6 WriteAPixel( x + x0, -y + y0, color); // Octant 7 WriteAPixel( y + x0, -x + y0, color); // Octant 8 y++; if (decisionOver2 <= 0) { decisionOver2 += 2 * y + 1; // Change in decision criterion for y -> y+1 } else { x--; decisionOver2 += 2 * (y - x) + 1; // Change for y -> y+1, x -> x-1 } } }
void TestVLine(int x1, int y1, int length, int Colour) { int i; for(i = y1; i < y1+length; i++ ) WriteAPixel(x1, i, Colour); }
void TestHLine(int x1, int y1, int length, int Colour) { int i; for(i = x1; i < x1+length; i++ ) WriteAPixel(i, y1, Colour); }