Code:

#include<stdio.h>
#include<dos.h> //for delay
#include<graphics.h>
#include<conio.h> // for getch and clrscr
void pendn(char); /*acts as if pen is down*./
void penup(char);
void erase(char);
void cur(int,int,int); /*cursor function*/
void (*p)(); /*pointer to call functions*/
void ul(int,int,int,int); /*to draw a line*/
static int x,y,x1=0,y1=0,x2,y2;
int main()
{
int gd=DETECT,gm;
char ch;int tmpx,tmpy,tmpr,st,et,i,j;
initgraph(&gd,&gm,"");
delay(1000);
x=getmaxx()/2;
y=getmaxy()/2;
rectangle(x+1,y+1,x-1,y-1);
p=penup;
do{
ch=getch();
if (ch=='s')
{
if(x1==0)
{ x1=x;y1=y;
putpixel(x,y,15);
printf("\r%d%d\t",x1,y1);
}
else
{
x2=x;y2=y;
printf("\r%d%d\t",x2,y2);
ch=getch();
if(ch=='1')
ul(x1,y1,x2,y2);
else if(ch=='2')
{
tmpx=(x1+x2)/2;
tmpy=(y1+y2)/2;
if(y1==y2)
tmpr=x2-tmpx;
if(x1==x2)
tmpr=y2-tmpy;
if(tmpr<0)
tmpr*=-1;
printf("\r enter angles:");
scanf("%d%d",&st,&et);
setcolor(15);
arc(tmpx,tmpy,st,et,tmpr);
putpixel(x1,y1,15);
putpixel(x2,y2,15);
}
x1=0;
}
}
else
{
if(ch=='1')
{
ch=getch();
printf("\r pendown ");
cur(x,y,0);
p=pendn;
}
else if(ch=='2')
{
ch=getch();
printf("\r penup ");
p=penup;
}
else if(ch=='3')
{
ch=getch();
printf("\r eraser on");
p=erase;
}
(*p)(ch);
}
}while(ch!='i');
for(j=0;j<6;j++)
for(i=0;i<6;i++)
{
clrscr();
settextstyle(1,0,i);
settextjustify(1,1);
outtextxy(getmaxx()/2,getmaxy()/2,"an elemeNtal corp :))");
sound(200*j-100*i);
delay(50);
}
nosound();
getch();
return 0;
}
void pendn(char ch)
{
switch(ch)
{
case 'w' :putpixel(x,y-1,15);y--;break;
case 'x' :putpixel(x,y+1,15);y++;break;
case 'a' :putpixel(x-1,y,15);x--;break;
case 'd' :putpixel(x+1,y,15);x++;break;
case 'q' :putpixel(x-1,y-1,15);y--;x--;break;
case 'e' :putpixel(x+1,y-1,15);y--;x++;break;
case 'z' :putpixel(x-1,y+1,15);y++;x--;break;
case 'c' :putpixel(x+1,y+1,15);y++;x++;break;
}
}
void penup(char ch)
{
cur(x,y,0);
switch(ch)
{
case 'w' :y--;break;
case 'x' :y++;break;
case 'a' :x--;break;
case 'd' :x++;break;
case 'q' :y--;x--;break;
case 'e' :y--;x++;break;
case 'z' :y++;x--;break;
case 'c' :y++;x++;break;
}
cur(x,y,15);
}
void erase(char ch)
{
cur(x,y,0);
switch(ch)
{
case 'w' :putpixel(x,y-1,0);y--;break;
case 'x' :putpixel(x,y+1,0);y++;break;
case 'a' :putpixel(x-1,y,0);x--;break;
case 'd' :putpixel(x+1,y,0);x++;break;
case 'q' :putpixel(x-1,y-1,0);y--;x--;break;
case 'e' :putpixel(x+1,y-1,0);y--;x++;break;
case 'z' :putpixel(x-1,y+1,0);y++;x--;break;
case 'c' :putpixel(x+1,y+1,0);y++;x++;break;
}
cur(x,y,15);
}
void cur(int x,int y,int col)
{
setcolor(col);
rectangle(x+1,y+1,x-1,y-1);
}
void ul(int x1,int y1,int x2,int y2)
{
int i,y,t;float m;
if(x1>x2 || y1>y2)
{
t=x1;x1=x2;x2=t;
t=y1;y1=y2;y2=t;
}
if(x1==x2)
for(i=y1;i<=y2;i++)
{
putpixel(x1,i,15);
delay(100);
}
else
{
m=(y2-y1)/(x2-x1);
for(i=x1;i<=x2;i++)
{
y=(m*(i-x1))+y1;
putpixel(i,y,15);
delay(100);
}
}
}