Drawing in 2 dimensions



     This program is also one of my priced possessions.It allows you to draw on the screen using cursor keys.An on-screen co-ordinate system allows distances to be evaluated to the accuracy of a pixel.You can draw in 8 directions.The code is very effecient and is free from bugs.It should work perfectly on a Turbo-C compiler.



#include<graphics.h>
#include<stdio.h>
#include<dos.h>
main()
{
int gd=DETECT,gm,i,j,a;
int x,y,count;
initgraph(&gd,&gm,"c:\\tc\\bgi");
setcolor(RED);
outtextxy(30,30,"PRESS ESC TO QUIT");
outtextxy(30,40,"USE CURSOR KEYS TO DRAW");
outtextxy(30,50,"USE PgUp PgDown Home End keys TO DRAW OBLIQUE LINES");
outtextxy(30,60,"USE SPACEBAR TO TOGGLE BETWEEN DRAW AND ERASE MODE");
x=getmaxx()/2;
y=getmaxy()/2;
setcolor(LIGHTMAGENTA);
count=0;
while(1)
{
gotoxy(70,3);
printf("x:%3d",x);
gotoxy(70,5);
printf("y:%3d",y);
gotoxy(x,y);
a=getkey();
if(a==72)
line(x,y,x,y=y-1);
if(a==80)
line(x,y,x,y=y+1);
if(a==75)
line(x,y,x-=1,y);
if(a==77)
line(x,y,x+=1,y);
if(a==73)
line(x,y,x+=1,y-=1);
if(a==71)
line(x,y,x-=1,y-=1);
if(a==79)
line(x,y,x-=1,y+=1);
if(a==81)
line(x,y,x+=1,y+=1);
if(a==57)
{
setcolor(BLACK);
count++;
}
if(count%2==0)
setcolor(LIGHTMAGENTA);
if(a==1)
break;
}
}


getkey()
{
union REGS i,o;
while(!kbhit());
i.h.ah=0;
int86(22,&i,&o);
return(o.h.ah);
}



Go to the main web page click here!!!

Hosted by www.Geocities.ws

1