/* avivA Starkman * May 30, 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 */ void ShakeScreen(int *x, int *y, int lines); main() { int locx, locy; /* current screen position */ int oldcol = 0; /* save color of old location */ char ch; int lines = 1; /* line drawing = ON */ 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, lines); ch = getch(); while ((ch != 'q') && (ch != 'Q')) { switch (ch) { /* clear screen */ case 'c': case 'C': clrscrn2(0xf0); ShakeScreen(&locx, &locy, lines); break; /* toggle line drawing */ case 't': case 'T': pen_color(TITLECOLOR); if (lines) { lines = 0; move_to(292, 179); plots("OFF"); } else { lines = 1; move_to(292, 179); plots("ON "); } pen_color(LINECOLOR); move_to(locx, locy); break; /* move up */ case 'k': case 'K': if (locy >= STEP) { if (!lines) { /* restore old pixel */ pen_color(oldcol); setpixel(locx, locy); pen_color(LINECOLOR); } locy -= STEP; if (lines) line_to(locx, locy); else { move_to(locx, locy); oldcol = getpixel(locx, locy); /* save old pixel */ } } break; /* move down */ case 'j': case 'J': if (locy <= MAXY - STEP) { if (!lines) { pen_color(oldcol); setpixel(locx, locy); pen_color(LINECOLOR); } locy += STEP; if (lines) line_to(locx, locy); else { move_to(locx, locy); oldcol = getpixel(locx, locy); } } break; /* move left */ case 'h': case 'H': if (locx >= STEP) { if (!lines) { pen_color(oldcol); setpixel(locx, locy); pen_color(LINECOLOR); } locx -= STEP; if (lines) line_to(locx, locy); else { move_to(locx, locy); oldcol = getpixel(locx, locy); } } break; /* move right */ case 'l': case 'L': if (locx <= MAXX - STEP) { if (!lines) { pen_color(oldcol); setpixel(locx, locy); pen_color(LINECOLOR); } locx += STEP; if (lines) line_to(locx, locy); else { move_to(locx, locy); oldcol = getpixel(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, int lines) { /* ShakeScreen re-initializes the screen for a new drawing */ pen_color(TITLECOLOR); /* print title */ move_to(100, 0); plots("Electro-Sketch"); move_to (8, 116); /* print instruction box */ plots("Left:"); move_to(8, (116 + 1*11)); plots("Right:"); move_to(8, (116 + 2*11)); plots("Up:"); move_to(8, (116 + 3*11)); plots("Down:"); move_to(8, (116 + 4*11)); plots("Toggle:"); move_to(8, (116 + 5*11)); plots("Clear:"); move_to(8, (116 + 6*11)); plots("Quit:"); pen_color(BOXCOLOR); move_to(0, 108); box(87, 89, 0); move_to(72, 116); plotch('H'); move_to(72, (116 + 1*11)); plotch('L'); move_to(72, (116 + 2*11)); plotch('K'); move_to(72, (116 + 3*11)); plotch('J'); move_to(72, (116 + 4*11)); plotch('T'); move_to(72, (116 + 5*11)); plotch('C'); move_to(72, (116 + 6*11)); plotch('Q'); move_to(132, 190); /* print our names */ plots("By: Doug, Chris & Aviva"); move_to(236, 179); /* print line status */ plots("Lines:"); pen_color(TITLECOLOR); move_to(292, 179); if (lines) plots("ON "); else plots("OFF"); 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); }