static void vLine(int fd, int x0, int y0, int y1) { int bak; // printf("vLine: %d %d %d\n", x0, y0, y1); if (((PGDC) fd)->ps != PS_SOLID) { error("Only PS_SOLID is supported in %s", __FUNCTION__); } // x and y have been already fit to dc if(y0 > y1) { bak = y1; y1 = y0; y0 = bak; } while(y1 >= y0) { lcd_point(fd, x0, y0); y0++; } return; }
static void hLine(int fd, int x0, int y0, int x1) { int bak; PGDC pgdc = (PGDC) fd; int sep = 0; // printf("hLine: %d %d %d\n", x0, y0, x1); // x and y have been already fit to dc if (x0 > x1) { bak = x1; x1 = x0; x0 = bak; } lcd_point(fd, x0, y0); x0++; if (x0 >= x1) return; while (x0 != x1) { if (pgdc->ps == PS_DOT) { if ((sep & 0x3) == 0x3) lcd_point(fd, x0, y0); sep ++; } else if (pgdc->ps == PS_SOLID) { lcd_point(fd, x0, y0); } x0 ++; } return; }
void drawBackground(Position *stars){ int row,col,xPos = 0; lcd_fillScreen(BLACK); // Fill stars for (row = stars->y; row < DISPLAY_HEIGHT; row += STAR_SPACING_HEIGHT) { for (col = stars->x; col < DISPLAY_WIDTH; col++) { if (xPos%STAR_SPACING_WIDTH == /*(row%2)*/ 0) { lcd_point(col,row,WHITE); } xPos++; } } // Increment for the next time if (stars->y == STAR_SPACING_HEIGHT*2) { stars->y = 0; } else { stars->y++; } }
void grph_line_bound(int fd, int x0, int y0, int x1, int y1, int yl, int yu) { short dx = 0, dy = 0; signed char dx_sym = 0, dy_sym = 0; short dx_x2 = 0, dy_x2 = 0; short di = 0; // PGDC pgdc = (PGDC) fd; //printf("line: %d %d %d\n", pgdc->x, pgdc->cx, pgdc->xres); dx = x1-x0; dy = y1-y0; if(dx == 0) /* vertical line */ { if (y0 < yl && y1 < yl) return; if (y0 > yu && y1 > yu) return; if (y0 < yl) y0 = yl; if (y0 > yu) y0 = yu; if (y1 < yl) y1 = yl; if (y1 > yu) y1 = yu; vLine(fd, x0, y0, y1); return; } if(dx > 0) { dx_sym = 1; } else { dx_sym = -1; } if(dy == 0) /* horizontal line */ { if (y0 < yl) return; if (y0 > yu) return; hLine(fd, x0, y0, x1); return; } if (((PGDC) fd)->ps != PS_SOLID) { error("Only PS_SOLID is supported in %s", __FUNCTION__); } if(dy > 0) { dy_sym = 1; } else { dy_sym = -1; } dx = dx_sym*dx; dy = dy_sym*dy; dx_x2 = dx*2; dy_x2 = dy*2; if(dx >= dy) { di = dy_x2 - dx; while(x0 != x1) { if (y0 >= yl && y0 <= yu) { lcd_point(fd, x0, y0); } x0 += dx_sym; if(di<0) { di += dy_x2; } else { di += dy_x2 - dx_x2; y0 += dy_sym; } } if (y0 >= yl && y0 <= yu) { lcd_point(fd, x0, y0); } } else { di = dx_x2 - dy; while(y0 != y1) { if (y0 >= yl && y0 <= yu) { lcd_point(fd, x0, y0); } y0 += dy_sym; if(di < 0) { di += dx_x2; } else { di += dx_x2 - dy_x2; x0 += dx_sym; } } if (y0 >= yl && y0 <= yu) { lcd_point(fd, x0, y0); } } return; }
void grph_line(int fd, int x0, int y0, int x1, int y1) { short dx = 0, dy = 0; signed char dx_sym = 0, dy_sym = 0; short dx_x2 = 0, dy_x2 = 0; short di = 0; // PGDC pgdc = (PGDC) fd; //printf("line: %d %d %d\n", pgdc->x, pgdc->cx, pgdc->xres); /* x0 += pgdc->x; y0 += pgdc->y; x1 += pgdc->x; y1 += pgdc->y; */ dx = x1-x0; dy = y1-y0; /* x += pgdc->x; y += pgdc->y; if (cx<0) cx = 0; if (cy<0) cy = 0; if (x > pgdc->x+pgdc->cx) return; else if (x+cx > pgdc->x+pgdc->cx) cx = pgdc->x+pgdc->cx -1 - x; if (y > pgdc->y+pgdc->cy) return; else if (y+cy > pgdc->y+pgdc->cy) cy = pgdc->y+pgdc->cy -1 - y; */ if(dx == 0) /* vertical line */ { /* if (x0 < pgdc->x || x0 > pgdc->x + pgdc->cx) return; y0 = (y0 < pgdc->y) ? pgdc->y : y0; y0 = (y0 >= pgdc->y+pgdc->cy) ? pgdc->y+pgdc->cy-1 : y0; y1 = (y1 < pgdc->y) ? pgdc->y : y1; y1 = (y1 >= pgdc->y+pgdc->cy) ? pgdc->y+pgdc->cy-1 : y1;*/ vLine(fd, x0, y0, y1); return; } if(dx > 0) { dx_sym = 1; } else { dx_sym = -1; } if(dy == 0) /* horizontal line */ { /* if (y0 < pgdc->y || y0 > pgdc->y + pgdc->cy) return; printf("grph_line %d %d %d %d\n", x0, x1, pgdc->x, pgdc->cx); x0 = (x0 < pgdc->x) ? pgdc->x : x0; x0 = (x0 >= pgdc->x+pgdc->cx) ? pgdc->x+pgdc->cx-1 : x0; x1 = (x1 < pgdc->x) ? pgdc->x : x1; x1 = (x1 >= pgdc->x+pgdc->cx) ? pgdc->x+pgdc->cx-1 : x1;*/ hLine(fd, x0, y0, x1); return; } if (((PGDC) fd)->ps != PS_SOLID) { error("Only PS_SOLID is supported in %s", __FUNCTION__); } if(dy > 0) { dy_sym = 1; } else { dy_sym = -1; } dx = dx_sym*dx; dy = dy_sym*dy; dx_x2 = dx*2; dy_x2 = dy*2; if(dx >= dy) { di = dy_x2 - dx; while(x0 != x1) { lcd_point(fd, x0, y0); x0 += dx_sym; if(di<0) { di += dy_x2; } else { di += dy_x2 - dx_x2; y0 += dy_sym; } // if (x0<0 || x0>=pgdc->cx) break; // if (y0<0 || y0>=pgdc->cy) break; } lcd_point(fd, x0, y0); } else { di = dx_x2 - dy; while(y0 != y1) { lcd_point(fd, x0, y0); y0 += dy_sym; if(di < 0) { di += dx_x2; } else { di += dx_x2 - dy_x2; x0 += dx_sym; } // if (x0<0 || x0>=pgdc->cx) break; // if (y0<0 || y0>=pgdc->cy) break; } lcd_point(fd, x0, y0); } return; }
int drawBall(BALL* ball) { int position; do { int x = ball->old_x; int y = ball->old_y; if (x > ball->x) position = LEFT; else if (x < ball->x) position = RIGHT; else if (y > ball->y) position = DOWN; else if (y < ball->y) position = UP; else position = 0; switch (position) { case 0: { lcd_point(x-1, y+2, 1); lcd_point(x-0, y+2, 1); lcd_point(x+1, y+2, 1); lcd_point(x-2, y+1, 1); lcd_point(x-1, y+1, 1); lcd_point(x+0, y+1, 1); lcd_point(x+1, y+1, 1); lcd_point(x+2, y+1, 1); lcd_point(x-2, y+0, 1); lcd_point(x-1, y+0, 1); lcd_point(x+0, y+0, 1); lcd_point(x+1, y+0, 1); lcd_point(x+2, y+0, 1); lcd_point(x-2, y-1, 1); lcd_point(x-1, y-1, 1); lcd_point(x+0, y-1, 1); lcd_point(x+1, y-1, 1); lcd_point(x+2, y-1, 1); lcd_point(x-1, y-2, 1); lcd_point(x-0, y-2, 1); lcd_point(x+1, y-2, 1); break; } case UP: // up { lcd_point(x-1, y+3, 1); lcd_point(x-0, y+3, 1); lcd_point(x+1, y+3, 1); lcd_point(x-2, y+2, 1); lcd_point(x+2, y+2, 1); lcd_point(x-2, y-1, 0); lcd_point(x+2, y-1, 0); lcd_point(x-1, y-2, 0); lcd_point(x-0, y-2, 0); lcd_point(x+1, y-2, 0); ball->old_y++; break; } case DOWN: // down { lcd_point(x-1, y-3, 1); lcd_point(x-0, y-3, 1); lcd_point(x+1, y-3, 1); lcd_point(x-2, y-2, 1); lcd_point(x+2, y-2, 1); lcd_point(x-2, y+1, 0); lcd_point(x+2, y+1, 0); lcd_point(x-1, y+2, 0); lcd_point(x-0, y+2, 0); lcd_point(x+1, y+2, 0); ball->old_y--; break; } case RIGHT: // right { lcd_point(x+3, y-1, 1); lcd_point(x+3, y+0, 1); lcd_point(x+3, y+1, 1); lcd_point(x+2, y-2, 1); lcd_point(x+2, y+2, 1); lcd_point(x-1, y-2, 0); lcd_point(x-1, y+2, 0); lcd_point(x-2, y-1, 0); lcd_point(x-2, y+0, 0); lcd_point(x-2, y+1, 0); ball->old_x++; break; } case LEFT: // left { lcd_point(x-3, y-1, 1); lcd_point(x-3, y+0, 1); lcd_point(x-3, y+1, 1); lcd_point(x-2, y-2, 1); lcd_point(x-2, y+2, 1); lcd_point(x+1, y-2, 0); lcd_point(x+1, y+2, 0); lcd_point(x+2, y-1, 0); lcd_point(x+2, y+0, 0); lcd_point(x+2, y+1, 0); ball->old_x--; break; } } } while ((ball->x != ball->old_x) || (ball->y != ball->old_y)); return ball->y; } // end drawBall