/* avivA Starkman * May 16, 1996 * "Electro-Sketch": An Electronic Etch-A-Sketch * written for PowerC compiler */ #include #include #define STEP 2 /* line increment amount */ #define MAXX 319 /* screen size for CGA_320 */ #define MAXY 199 #define BGCOLOR 1 /* background color: blue */ #define PALETTE 1 /* palette: cyan/magenta/white */ #define TITLECOLOR 1 /* title color: cyan */ #define BOXCOLOR 2 /* box color: magenta */ #define LINECOLOR 3 /* line color: white */ /* colors used to be [8, 0, 3, 1]: gray, brown, green */ void ShakeScreen(int *x, int *y); main() { int locx, locy; /* current screen position */ char ch; if (setvmode(CGA_320) != CGA_320) { printf ("ERROR: This program requires CGA, EGA, or VGA card\n"); exit(1); } else { setcolor(BGCOLOR, PALETTE); ShakeScreen(&locx, &locy); ch = getch(); while ((ch != 'q') && (ch != 'Q')) { switch (ch) { /* clear screen */ case 'c': case 'C': clrscrn2(0xf0); ShakeScreen(&locx, &locy); break; /* move up */ case 'k': case 'K': if (locy >= STEP) { locy -= STEP; line_to(locx, locy); } break; /* move down */ case 'j': case 'J': if (locy <= MAXY - STEP) { locy += STEP; line_to(locx, locy); } break; /* move left */ case 'h': case 'H': if (locx >= STEP) { locx -= STEP; line_to(locx, locy); } break; /* move right */ case 'l': case 'L': if (locx <= MAXX - STEP) { locx += STEP; line_to(locx, locy); } } /* end switch */ /* show current position in title color */ pen_color(TITLECOLOR); setpixel(locx, locy); pen_color(LINECOLOR); ch = getch(); } /* end while */ setvmode(DEFAULTMODE); exit(0); } /* end else */ } /* end main */ void ShakeScreen(int *x, int *y) { /* ShakeScreen re-initializes the screen for a new drawing */ pen_color(TITLECOLOR); /* print title */ move_to(100, 0); plots("Electro-Sketch"); move_to (8, 127); /* print instruction box */ plots("Left:"); move_to(8, (127 + 1*11)); plots("Right:"); move_to(8, (127 + 2*11)); plots("Up:"); move_to(8, (127 + 3*11)); plots("Down:"); move_to(8, (127 + 4*11)); plots("Clear:"); move_to(8, (127 + 5*11)); plots("Quit:"); pen_color(BOXCOLOR); move_to(0, 120); box(81, 77, 0); move_to(64, 127); plotch('H'); move_to(64, (127 + 1*11)); plotch('L'); move_to(64, (127 + 2*11)); plotch('K'); move_to(64, (127 + 3*11)); plotch('J'); move_to(64, (127 + 4*11)); plotch('C'); move_to(64, (127 + 5*11)); plotch('Q'); move_to(132, 190); /* print our names */ plots("By: Doug, Chris & Aviva"); pen_color(TITLECOLOR); /* print title */ move_to(160,100); /* go to center of screen */ *x = 160; /* initialize loc variables */ *y = 100; setpixel(*x, *y); /* show current position */ pen_color(LINECOLOR); }