/************************************************************************/ /* Draw a line with a pattern using the 'slow' algorithm */ /************************************************************************/ slow_pattern_line(x0, y0, x1, y1, color,pattern) int x0, y0, x1, y1, color, pattern; { int x, y; static int mask[16] = { 0x8000,0x4000,0x2000,0x1000, 0x0800,0x0400,0x0200,0x0100, 0x0080,0x0040,0x0020,0x0010, 0x0008,0x0004,0x0002,0x0001}; /*--- Draw degenerate line (pixel) */ if (x0 == x1 && y0 == y1) /* Draw a single pixel */ { if (mask[x0 & 15] & pattern) pixel_write(x0, y0, color); } /*--- Draw lines with dx > dy */ else if (abs(x1 - x0) >= abs(y1 - y0)) { /* Swap end points */ if (x1 < x0) { x = x1; y = y1; x1 = x0; y1 = y0; x0 = x; y0 = y; } for (x = x0; x <= x1; x++) /* Loop over x coord */ { /* Compute y using x */ y = y0 + ((x - x0)*(long)(y1 - y0))/(x1 - x0); if (mask[x & 15] & pattern) pixel_write(x,y,color); /* Draw next point */ } } /*--- Draw lines with dy > dx */ else { if (y1 < y0) /* Swap end points */ { x = x1; y = y1; x1 = x0; y1 = y0; x0 = x; y0 = y; } for (y = y0; y <= y1; y++) /* Loop over y coord */ { /* Compute x using y */ x = x0 + ((y - y0)*(long)(x1 - x0))/(y1 - y0); if (mask[y & 15] & pattern) pixel_write(x,y,color); /* Draw next point */ } } }