Circle.c
#include
#include
void plotCircle(int,int,int,int);
void main()
{
int gd=DETECT,gm,xc,yc;
int x,y,r,p;
initgraph(&gd,&gm,"e:\\tc\\bgi;");
printf("\n\t\t01.CIRCLE DRAWING\n\t\t~~~~~~~~~~~~~~~~~\n\n\n\n");
printf("Enter the center for circle(x,y): ");
scanf("%d%d",&xc,&yc);
printf("\nEnter the radius: ");
scanf("%d",&r);
printf("\nOutput:\n");
x=0;y=r;
p=(-(2*r));
while(x
#include
void elipse(int,int,int,int);
void main()
{
//int gd=DETECT,gm,xc,yc;
int gm,gd=DETECT;
int xc,yc,x1,x2;
clrscr();
initgraph(&gd,&gm,"e:\\tc\\bgi;");
printf("\n\t\t01.ELLIPSE DRAWING");
printf("\n\t\t~~~~~~~~~~~~~~~~~~\n\n\nEnter the order of ellipse: ");
scanf("%d%d",&xc,&yc);
printf("\nEnter the major and minor axis: ");
scanf("%d%d",&x1,&x2);
elipse(xc,yc,x1,x2);
//getch();
closegraph();
}
void elipse(int xc,int yc,int rx,int ry)
{
int x1,y1,j;
for(j=0;j<359;j++) { x1=xc+rx*cos(j); y1=yc+ry*sin(j); putpixel(x1,y1,10); } getch(); } Line.c #include
#include
#include
#include
void main()
{
int k,t,xa,ya,xb,yb,dx,dy,x,y,p,x1;
int gd=DETECT,gm;
initgraph(&gd,&gm,"e:\\tc\\bgi;");
printf("\n\t\t03.LINE DRAWING");
printf("\n\t\t~~~~~~~~~~~~~~~\n\n\n");
printf("Enter the coordinates (Starting points): ");
scanf("%d%d",&xa,&ya);
printf("Enter the coordinates ( Ending points): ");
scanf("%d%d",&xb,&yb);
/*printf("\nEnter the thickness (give above 200): ");
scanf("%d",&t);
*/
dx=abs(xa-xb);
dy=abs(ya-yb);
p=(2*dy)-dx;
if(xa>xb)
{
x=xa;
y=ya;
x1=xa;
}
else
{
x=xa;
y=ya;
x1=xb;
}
//putpixel(x,y,5);
while(x
#include
#include
#include
void main()
{
float sx,sy;
int x1,y1,x,y;
int gm,gd=DETECT;
clrscr();
initgraph(&gd,&gm,"e:\tc\bgi");
settextstyle(7,0,5);
outtextxy(20,10,"RECTANGLE SCALING");
getch();
printf("Enter the value of x1 & y1: ");
scanf("%d%d",&x1,&y1);
printf("Enter the value of x & y: ");
scanf("%d%d",&x,&y);
printf("Enter the scaling factor: ");
scanf("%d%d",&sx,&sy);;
cleardevice();
rectangle(0,0,639,749);
settextstyle(7,0,3);
outtextxy(20,20,"Rectangle before & after scaling");
rectangle(x1,y1,x,y);
x1=abs(x-x1);
x=x+(x1*sx);
y1=abs(y-y1);
y=y+(y1*sy);
setlinestyle(1,1,1);
setcolor(5);
rectangle(x1,y1,x,y);
getch();
}
RectRotation.c
#include
#include
#include
#include
void main()
{
int xr,yr,xa,ya,xb,yb,xd,yd;
int xa1,ya1,xb1,yb1,xc1,yc1,xd1,yd1,xc,yc,xjyj,ang;
int gm,gd=DETECT;
clrscr();
initgraph(&gd,&gm,"c:\tc\bgi");
printf("\t2D-ROTATION\n");
printf("\t~~~~~~~~~~~\n\n\n");
printf("\nEnter the value of xa & ya: ");
scanf("%d%d",&xa,&ya);
printf("\nEnter the value of xb & yb: ");
scanf("%d%d",&xb,&yb);
printf("\nEnter the value of xc & yc: ");
scanf("%d%d",&xc,&yc);
printf("\nEnter the value of xd & yd: ");
scanf("%d%d",&xd,&yd);
printf("\nEnter the value of xr & yr: ");
scanf("%d%d",&xr,&yr);
printf("\nEnter the angle");
scanf("%d",&ang);
setcolor(CYAN);
setfillstyle(CLOSE_DOT_FILL,GREEN);
line(xa,ya,xb,yb);
line(xb,yb,xc,yc);
line(xc,yc,xd,yd);
line(xd,yd,xa,ya);
ang=ang*(22/7)*180;
xa1=xr+(xa-xr)*cos(ang)-(ya-yr)*sin(ang);
ya1=yr+(xa-xr)*sin(ang)+(ya-yr)*cos(ang);
xb1=xr+(xb-xr)*cos(ang)-(yb-yr)*sin(ang);
yb1=yr+(xb-xr)*sin(ang)+(yb-yr)*cos(ang);
xc1=xr+(xc-xr)*cos(ang)-(yc-yr)*sin(ang);
yc1=yr+(xc-xr)*sin(ang)+(yc-yr)*cos(ang);
xd1=xr+(xd-xr)*cos(ang)-(yd-yr)*sin(ang);
yd1=yr+(xd-xr)*sin(ang)+(yd-yr)*cos(ang);
line(xa1,ya1,xb1,yb1);
line(xb1,yb1,xc1,yc1);
line(xc1,yc1,xd1,yd1);
line(xd1,yd1,xa1,ya1);
getch();
closegraph();
}
RectReflection.c
#include
#include
#include
#include
void main()
{
float sx,sy;
int xa,ya,xb,yb,xa1,ya1,xb1,yb1,a,b,c,d;
char z;
int gm,gd=DETECT;
clrscr();
initgraph(&gd,&gm,"e:\tc\bgi");
settextstyle(7,0,5);
outtextxy(50,10,"REFLECTION");
getch();
xx:
line(0,250,650,250);
line(300 ,0,300,600);
printf("Enter the value for xa,ya,xb,yb: ");
scanf("%d%d%d%d",&xa,&ya,&xb,&yb);
line(xa,ya,xb,yb);
printf("Reflection alongx or y axis (x/y): ");
scanf("%s",&z);
if(z=='x')
{
a=250-xa;
b=250-xb;
ya1=250+a;
yb1=250+b;
line(xa,ya1,xb,yb1);
}
else if(z=='y')
{
c=300-ya;
d=300-yb;
yb1=300+d;
xa1=300+c;
line(xa1,ya,yb1,yb);
}
printf("\nStill continue (y/n )??: ");
scanf("%s",&z);
if(z=='y'||z=='Y')
{
clearviewport();
goto xx;
}
else
{
exit(0);
getch();
closegraph();
}
}
Program 03
LineClipping.c
#include
#include
#include
#include
int m,x1,x2,y1,y2,i,xmax,ymax,xmin,ymin;
int x,y,a,b,acc,rej,p[5],q[5],r[10];
void main()
{
int j,don,dis,gm,gd=DETECT;
initgraph(&gd,&gm,"c:\tc\bgi");
settextstyle(4,0,5);
outtextxy(50,4,"LINE CLIPPING");
printf("\n\n\n\n\n\nEnter the value of xmin,ymin,xmax,ymax,x1,y1,x2,y2:\n ");
scanf("%d%d%d%d%d%d%d%d",&xmin,&ymin,&xmax,&ymax,&x1,&y1,&x2,&y2);
getch();
cleardevice();
settextstyle(7,0,6);
outtextxy(20,10,"BEFORE CLIPPING");
line(x1,y1,x2,y2);
rectangle(xmin,ymin,xmax,ymax);
getch();
cleardevice();
//settextstyle(7,0,7);
outtextxy(50,10,"AFTER CLIPPING");
rectangle(xmin,ymin,xmax,ymax);
don=0;
dis=0;
while(don==0)
{
x=x1;
y=y1;
if(y>ymax)
p[1]=1;
else
p[1]=0;
if(y
p[3]=1;
else
p[3]=0;
if(x
q[1]=1;
else
q[1]=0;
if(y
q[3]=1;
else
q[3]=0;
if(x
{
a=x1;
b=y1;
x1=x2;
y1=y2;
x2=a;
y2=b;
for(j=1;j<=4;j++) { r[j]=p[j]; p[j]=q[j]; q[j]=r[j]; } } if(x1!=x2) { m=(y2-y1)/(x2-x1); if(p[4]==1) { y1=y1+(xmin-x1)*m; x1=xmin; } else if(p[3]==1) { y1=y1+(xmax-x1)*m; x1=xmax; } else if(p[2]==1) { x1=x1+(ymin-y1)/m; y1=ymin; } else if(p[1]==1) { x1=x1+(ymax-y1)/m; y1=ymax; } } } } } if(dis==1) { setcolor(RED); rectangle(xmin,ymin,xmax,ymax); setcolor(YELLOW); line(x1,y1,x2,y2); } else { if(dis==0) rectangle(xmin,ymin,xmax,ymax); } getch(); } Program 04 textClipping.cpp #include
#include
#include
#include
#include
class WindowCoordinates
{
public:
float x_min;
float y_min;
float x_max;
float y_max;
WindowCoordinates(const float x1,const float y1,const float x2,const float y2)
{
x_min=x1;
y_min=y1;
x_max=x2;
y_max=y2;
}
};
void show_screen();
void show_clipped_text(const WindowCoordinates,const int,const int,const char*,const int,const int,const int);
void Rectangle(const int,const int,const int,const int);
void Line(const int,const int,const int,const int);
int main()
{
int driver=VGA;
int mode=VGAHI;
initgraph(&driver,&mode,"..\\Bgi");
show_screen();
WindowCoordinates WC(180,140,470,340);
setcolor(15);
Rectangle(WC.x_min,WC.y_min,WC.x_max,WC.y_max);
setcolor(7);
settextstyle(0,0,2);
outtextxy (160,160,"string 1");
outtextxy(250,300,"string 2");
settextstyle(0,1,2);
outtextxy(350,100,"string 3");
outtextxy(440,180,"string 4");
char key=NULL;
do
{
key=getch();
}
while(key!='c' && key!='c');
settextstyle(0,0,1);
setcolor(0);
outtextxy(163,450,"press 'c' to see the clipped text. ");
setcolor(15);
outtextxy(165,450,"--------------------------------");
setcolor(12);
outtextxy(213,450,"press any key to exit. ");
setcolor(10);
show_clipped_text(WC,160,160,"string 1",0,0,2);
show_clipped_text(WC,250,300,"string 2",0,0,2);
show_clipped_text(WC,350,100,"string 3",0,1,2);
show_clipped_text(WC,440,180,"string 4",0,1,2);
getch();
return 0;
}
void show_clipped_text(const WindowCoordinates wc,const int _x,const int _y,const char* String,const int font_style,const int text_direction,const int font_size)
{
settextstyle(font_style,text_direction,font_size);
int x=_x;
int y=_y;
int width;
int height;
int length=strlen(String);
if(text_direction==1)
y+=textwidth(String);
char Character[5]={NULL};
for(int count=0;count
{
x1=x_2;
y1=y_2;
x2=x_1;
y2=y_1;
}
int dx=abs(x2-x1);
int dy=abs(y2-y1);
int inc_dec=((y2>=y1)?1:-1);
if(dx>dy)
{
int two_dy=(2*dy);
int two_dy_dx=(2*(dy-dx));
int p=((2*dy)-dx);
int x=x1;
int y=y1;
putpixel(x,y,color);
while(x
#include
#include
#include
void main()
{
int x0,y0,x1,y1,d1,d2,r,r1,gd=DETECT,gm;
int xa,ya,xb,yb;
initgraph(&gd,&gm,"c:\\tc\\bgi");
cleardevice();
settextstyle(7,0,6);
printf("Enter the value of x0 & y0: ");
scanf("%d%d",&x0,&y0);
printf("Enter the value of x1 & y1: ");
scanf("%d%d",&x1,&y1);
printf("Enter the value of d1 & d2: ");
scanf("%d%d",&d1,&d2);
printf("Enter the value of angle : ");
scanf("%d",&r1);
r=r1*(3.14)*180;
getch();
cleardevice();
printf("\nBefore Rotation: ");
bar3d(x0,y0,x1,y1,d1,d2);
getch();
xa=x0*cos(r)-y0*sin(r);
ya=y0*cos(r)+x0*sin(r);
xb=x1*cos(r)-y1*sin(r);
yb=y1*cos(r)+x1*sin(r);
setcolor(6);
printf("\nAFTER ROTATION");
bar3d(xa,ya,xb,yb,d1,d2);
getch();
}
2D Scaling.c
#include
#include
#include
#include
void set3dline(int,int,int,int);
void main()
{
int n,l,h,w,x1,y1,xa,ya,l1,h1;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\tc:\bgi");
printf("\t\t3D scaling\n\n\n");
printf("\n enter the x1,y1: ");
scanf("%d%d",&x1,&y1);
printf("Enter the length and height (l&h): ");
scanf("%d%d",&l,&h);
set3dline(x1,y1,l,h);
printf("enter the length and height for scaling");
scanf("%d%d",&l1,&h1);
l=l*l1;
h=h*h1;
set3dline(x1,y1,l,h);
}
void set3dline(int x1,int y1,int l,int h)
{
int x2,x3,x4,x5,x6,x7,x8;
int y2,y3,y4,y5,y6,y7,y8;
x2=x1+l;
y2=y1;
x3=x2;
y3=y2-h;
x4=x3-l;
y4=y3;
setlinestyle(SOLID_LINE,1,1);
//setcolor(5);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x4,y4);
line(x4,y4,x1,y1);
//getch();
x5=x1+l*cos(120);
y5=y1-l*sin(120);
x6=x2+l*cos(120);
y6=y2-l*cos(120);
x7=x3+l*cos(120);
y7=y3-l*sin(120);
x8=x4+l*cos(120);
y8=y4-l*sin(120);
//getch();
//setcolor(2);
line(x5,y5,x6,y6);
line(x6,y6,x7,y7);
line(x7,y7,x8,y8);
line(x8,y8,x5,y5);
//getch();
setlinestyle(DASHED_LINE,1,1);
//setcolor(3);
line(x1,y1,x5,y5);
line(x2,y2,x6,y6);
line(x3,y3,x7,y7);
line(x4,y4,x8,y8);
getch();
}
2D Translation.c
#include
#include
#include
#include
void main()
{
int l,h,x1,y1,xa,ya,gd=DETECT,gm,i,j;
initgraph(&gd,&gm,"c:\\tc:\\bgi");
printf("Enter x1 & y1: ");
scanf("%d%d",&x1,&y1);
printf("Enter the length & height (l,h): ");
scanf("%d%d",&l,&h);
set3Dline(x1,y1,l,h);
printf("Enter the translation factor (xa,ya): ");
scanf("%d%d",&xa,&ya);
x1=x1+xa;
y1=y1+ya;
set3Dline(x1,y1,l,h);
}
set3Dline(int x1,int y1,int l,int h)
{
int x2,x3,x4,x5,x6,x7,x8;
int y2,y3,y4,y5,y6,y7,y8;
x2=x1+l;
y2=y1;
x3=x2;
y3=y2-h;
x4=x3-l;
y4=y3;
setlinestyle(SOLID_LINE,1,1);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x4,y4);
line(x4,y4,x1,y1);
x5=x1+1*cos(120);
y5=y1-1*sin(120);
x6=x2+1*cos(120);
y6=y2-1*sin(120);
x7=x3+1*sin(120);
y7=y3-1*cos(120);
x8=x4+1*cos(120);
y8=y4-1*sin(120);
line(x5,y5,x6,y6);
line(x6,y6,x7,y7);
line(x7,y7,x8,y8);
line(x8,y8,x5,y5);
setlinestyle(DASHED_LINE,1,1);
setcolor(5);
line(x1,y1,x5,y5);
line(x2,y2,x6,y6);
line(x3,y3,x7,y7);
line(x4,y4,x8,y8);
getch();
return 0;
}
Program 06
colorConversion.c
#include
#include
#include
#include
void main()
{
float r,g,b,y,i,c,m,h,s,v;
int ch;
clrscr();
do
{
printf("\n\tCOLOR CONVERSION");
printf("\n1.RGB->YIQ\n2.YIQ->RGB\n3.RGB->CMY\n4.CMY->RGB\n5.RGB->HSV\n6.HSV->RGB\n7.Exit\n");
printf("Enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
int p,d,l;
float w[3][1],z[3][1];
float x[3][3]={.299,.587,.144,.596,-.275,-.321,.122,-.528,.311};
printf("Enter the RGB values (0-1) in matrix w: ");
for(p=0;p<3;p++) scanf("%f",&w[p][0]); for(p=0;p<3;p++) { for(d=0;d<1;d++) { z[p][d]=0; for(l=0;l<3;l++) z[p][d]=z[p][d]+x[p][l]*w[l][d]; } } printf("\nConverted Y value for R value %f is %f",w[0][0],z[0][0]); printf("\nConverted I value for G value %f is %f",w[1][0],z[1][0]); printf("\nConverted Q value for B value %f is %f",w[2][0],z[2][0]); } break; case 2: { int p,d,l; float w[3][1],z[3][1]; float x[3][3]={1.000,.956,.620,1.000,-.272,-.647,1.000,-1.108,1.705}; printf("Enter the YIQ values (0-1) in matrix w: "); for(p=0;p<3;p++) scanf("%f",&w[p][0]); for(p=0;p<3;p++) { for(d=0;d<1;d++) { z[p][d]=0; for(l=0;l<3;l++) z[p][d]=z[p][d]+x[p][l]*w[l][d]; } } printf("\nConverted R value for Y value %f is %f",w[0][0],z[0][0]); printf("\nConverted G value for I value %f is %f",w[1][0],z[1][0]); printf("\nConverted B value for Q value %f is %f",w[2][0],z[2][0]); } break; case 3: { int p,d,l; float w[3][1],z[3][1]; float x[3][1]={1,1,1}; printf("Enter the RGB values (0-1) in matrix w: "); for(p=0;p<3;p++) scanf("%f",&w[p][0]); for(p=0;p<3;p++) z[p][0]=x[p][0]-w[p][0]; printf("\nConverted C value for R value %f is %f",w[0][0],z[0][0]); printf("\nConverted M value for G value %f is %f",w[1][0],z[1][0]); printf("\nConverted Y value for B value %f is %f",w[2][0],z[2][0]); } break; case 4: { int p,d,l; float w[3][1],z[3][1]; float x[3][1]={1,1,1}; printf("Enter the CMY values (0-1) in matrix w: "); for(p=0;p<3;p++) scanf("%f",&w[p][0]); for(p=0;p<3;p++) z[p][0]=x[p][0]-w[p][0]; printf("\nConverted R value for C value %f is %f",w[0][0],z[0][0]); printf("\nConverted G value for M value %f is %f",w[1][0],z[1][0]); printf("\nConverted B value for Y value %f is %f",w[2][0],z[2][0]); } break; case 5: { float r,g,b,*h,*s,*v; float max,min,fmax,fmin; float delta; printf("Enter the RGB values (0-1): "); scanf("%f%f%f",&r,&g,&b); if(g>b)
{
fmax=g;
fmin=b;
}
else
{
fmax=r;
fmin=g;
}
if(r>fmax)
{
max=r;
min=fmax;
}
else
{
max=fmax;
min=r;
}
*v=max;
if(max!=0.0)
*s=delta/max;
else
*s=0.0;
if(*s==0.0)
*h=-1;
else
{
if(*s==max)
*h=(g-b)/delta;
else if(g==max)
*h=2+(b-r)/delta;
else if(b==max)
*h=4+(r=g)/delta;
*h*=60.0;
if(*h<0) *h+=360.0; *h/=360.0; } printf("\nConverted value of H value is %f",*h); printf("\nConverted value of S value is %f",*s); printf("\nConverted value of V value is %f",*v); } break; case 6: { int k; float h,s,v,*r,*g,*b; int aa,bb,cc,f; printf("Enter the h s v value: "); scanf("%f%f%f",&h,&s,&v); if(s==0) *r=*g=*b=v; else { if(h==1.0) h=0; h*=6.0; k=floor(h); f=h-k; aa=v*(1-s); bb=v*(1-(s*f)); cc=v*(1-(s*(1-f))); switch(k) { case 0: *r=v; *g=cc; *b=aa; break; case 1: *r=bb; *g=v; *b=aa; break; case 2: *r=aa; *g=v; *b=cc; break; case 3: *r=aa; *g=bb; *b=v; break; case 4: *r=cc; *g=aa; *b=v; break; case 5: *r=v; *g=aa; *b=bb; break; } } printf("\nConverted value of r value is %f",*r); printf("\nConverted value of g value is %f",*g); printf("\nConverted value of b value is %f",*b); } break; } } while(ch!=7); getch(); } Program 09 Parallelprojection.c #include
#include
#include
#include
#include
void main()
{
int p1,p2,x,y;
int gd=DETECT,gm;
int x0,y0,x1,y1,d1,d2;
initgraph(&gd,&gm,"c:\\tc\\bgi");
cleardevice();
settextstyle(7,0,5);
outtextxy(50,5,"3D OBJECT INPUT");
printf("\n\n\n\n\nEnter the i/p for 3D cube");
printf("\nEnter the value for x0,y0,x1,y1,d1,d2: ");
scanf("%d%d%d%d%d%d",&x0,&y0,&x1,&y1,&d1,&d2);
cleardevice();
setcolor(GREEN);
rectangle(0,0,639,479);
settextstyle(7,0,3);
bar3d(x0,y0,x1,y1,d1,d2);
printf("\n\n\n\n");
do
{
printf("\n1.TOP & BOTTOM VIEW");
printf("\n2.LEFT & RIGHT VIEW");
printf("\n3.FRONT & BACK VIEW");
printf("\nEnter your choice: ");
scanf("%d",&p1);
switch(p1)
{
case 1: cleardevice();
printf("\nTOP & BOTTOM VIEW\n\n");
line(x0,y0,x0+d1,y0-d1);
line(x0,y0,x1,y0);
line(x1,y0,x1+d1,y0-d1);
line(x1+d1,y0-d1,x0+d1,y0-d1);
break;
case 2: cleardevice();
printf("\nLEFT & RIGHT VIEW\n\n");
line(x1,y0,x1,y1);
line(x1,y0,x1+d1,y0-d1);
line(x1+d1,y0-d1,x1+d1,y1-d1);
line(x1,y1,x1+d1,y1-d1);
break;
case 3: cleardevice();
printf("\nFRONT & BACK VIEW\n\n");
line(x0,y0,x1,y0);
line(x0,y0,x0,y1);
line(x1,y0,x1,y1);
line(x0,y1,x1,y1);
break;
}
}while(p1<4); } PerspectiveProjection.c #include
#include
#include
#include
#include
void main()
{
char chr,chr1,chr2,chr3;
int gd=DETECT,gm;
int x0,y0,x1,y1,d1,d2,d11,d22,x11,x22,y11,y22;
int p1,p2,p3,p4,p5,p6;
initgraph(&gd,&gm,"c:\\tc\\bgi");
cleardevice();
settextstyle(4,0,5);
outtextxy(50,10,"3D OBJECT INPUT");
printf("\n\n\n\n\n\n\n\n\n\nEnter the value for 3D cubes:\n");
printf("\nEnter the value for x0,y0,x1,y1,d1,d2: ");
scanf("%d%d%d%d%d%d",&x0,&y0,&x1,&y1,&d1,&d2);
getch();
cleardevice();
setcolor(GREEN);
rectangle(0,0,639,479);
settextstyle(7,0,3);
bar3d(x0,y0,x1,y1,d1,d2);
settextstyle(7,0,3);
printf("\nEnter the value for p1 p2 p3 p4 p5 p6: ");
scanf("%d%d%d%d%d%d",&p1,&p2,&p3,&p4,&p5,&p6);
cleardevice();
setcolor(GREEN);
rectangle(0,0,639,479);
bar3d(x0,y0,x1,y1,d1,d2);
setcolor(BLUE);
outtextxy(20,20,"3D bar after perspective projection: ");
setcolor(YELLOW);
x11=x0+p1;
y11=y0+p2;
x22=x1+p3;
y22=y1+p4;
d11=d1+p5;
d22=d2+p6;
bar3d(x11,y11,x22,y22,d11,d22);
getch();
}
Program 10
runLengthEncoding.c
#include
#include
#include
struct
{
char ch;
int count;
}RLE[100];
void main()
{
int i,j,n,count;
char ch,str[100];
JINVIP:
clrscr();
printf("\tPROGRAMME TO IMPLEMENT RUN-LENGTH ENCODING TECH\n\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n\n");
printf("1.Run-Length Encoding\n2.Run-Length Decoding\n3.Exit\n\nEnter your choice: ");
ch=getche();
switch(ch)
{
case '1': printf("\nEnter the i/p sequence=> ");
gets(str);
printf("The o/p run-length Encoded Sequence is=> \n\n");
for(i=count=0,ch=*str;i
printf("\n\n[Press Enter to Terminate!!!]\n");
for(i=n=0;;i++,n++)
{
printf("\nEnter the character=> ");
RLE[i].ch=getche();
printf("\n");
if(RLE[i].ch==13)
break;
printf("\nEnter count for '%c'=> ",RLE[i].ch);
scanf("%d",&RLE[i].count);
}
printf("\nThe out put Run-Length Decoded Sequence is=> \n\n");
for(i=0;i
printf("\nPlease Enter a Valid Menu Choice in the Range [ 1-3 ]");
}
printf("\n\nPress any key to continue. . . .");
getch();
goto JINVIP;}
Program 11
circleMidPoint.c
#include
#include
#include
void dcircle(int,int,int);
void cliplot(int,int,int,int);
void main()
{
int gd=DETECT,gm;
int x,y,r;
printf("\nEnter the midpoint & radius:");
scanf("%d%d%d",&x,&y,&r);
initgraph(&gd,&gm," ");
dcircle(x,y,r);
getch();
closegraph();
}
void dcircle(int x1,int y1,int r)
{
int x=0,y=r,p=1-r,a,b,cenx,ceny;
cliplot(x1,y1,x,y);
while(x
#include
#include
#include
#include
#include
int main(void)
{
int gd=DETECT,gm;
int cenx,ceny;
float pk,a,b,x,y;
clrscr();
printf("\nEnter a&b:");
scanf("%f%f",&a,&b);
initgraph(&gd,&gm," ");
cenx=getmaxx()/2;
ceny=getmaxy()/2;
pk=b*b-b*a*a+0.25*a*a;
x=0;
y=b;
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);
while(2*x*b*b<=2*y*a*a) { if(pk<0) { x=x+1; y=y; pk=pk+2*x*b*b+3*b*b; } else { x=x+1; y=y-1; pk=pk+2*x*b*b+3*b-2*y*a*a+2*a*a; putpixel(cenx+x,ceny+y,WHITE); putpixel(cenx+x,ceny-y,WHITE); putpixel(cenx-x,ceny+y,WHITE); putpixel(cenx-x,ceny-y,WHITE); delay(40); } putpixel(cenx-x,ceny-y,WHITE); } while(y>0)
{
if(pk>0)
{
x=x;
y=y-1;
pk=pk-2*y*a*a+3*a*a;
}
else
{
x=x+1;
y=y-1;
pk=pk-2*y*a*a+3*a*a+2*x*b*b+2*b*b;
}
putpixel(cenx+x,ceny+y,WHITE);
putpixel(cenx+x,ceny-y,WHITE);
putpixel(cenx-x,ceny+y,WHITE);
putpixel(cenx-x,ceny-y,WHITE);
delay(40);
}
gotoxy(1,25);
printf("Press any key to exit");
getch();
closegraph();
return 0;
}