Escolar Documentos
Profissional Documentos
Cultura Documentos
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void main()
{
int menu=0;
int gdriver = DETECT, gmode, errorcode;
int maxx, maxy;
}
OUTPUT:
PROGRAM:
/* Pie-Chart */
#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
void main()
{
int gdriver=DETECT,gmode;
int w,c,m;
float div;
initgraph(&gdriver,&gmode,"");
printf("\nEnter the women numbers : ");
scanf("%d",&w);
printf("\nEnter the child numbers : ");
scanf("%d",&c);
printf("\nEnter the men numbers : ");
scanf("%d",&m);
cleardevice();
div=360.0/(w+c+m);
setcolor(2);
setfillstyle(SOLID_FILL,2);
pieslice(getmaxx()/2,getmaxy()/2,0,div*w,100);
setcolor(4);
outtextxy(getmaxx()/2-10,getmaxy()/2-50,"woman");
setfillstyle(LINE_FILL,4);
pieslice(getmaxx()/2,getmaxy()/2,div*w,div*(w+c),100);
setcolor(5);
outtextxy(getmaxx()/2-50,getmaxy()/2+20,"child");
setfillstyle(SLASH_FILL,5);
pieslice(getmaxx()/2,getmaxy()/2,div*(w+c),div*(w+c+m),100);
setcolor(2);
outtextxy(getmaxx()/2+50,getmaxy()/2+20,"men");
line(20,470,20,300);
line(2,460,500,460);
rectangle(30,460,60,350);
getch();
closegraph();
}
OUTPUT:
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
void main()
{
int gd=DETECT,gm,err;
float x1,y1,x2,y2,dx,dy,c,x,y,i;
initgraph(&gd,&gm,"");
printf("Enter the pair of vertices : ");
scanf("%f %f %f %f",&x1,&y1,&x2,&y2);
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>dy)
c=abs(dx);
else
c=abs(dy);
dx=(x2-x1)/c;
dy=(y2-y1)/c;
x=x1;y=y1;
putpixel(x,y,2);
for(i=0;i<x2||i<y2;i++)
{
x=x+dx;
y=y+dy;
putpixel(x,y,2);
}
getch();
closegraph();
}
OUTPUT:
PROGRAM:
OUTPUT:
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<dos.h>
void main()
{
int gdriver=DETECT,gmode,err;
float xt,st,ct,xp,yp,dt,x,y,r;
initgraph(&gdriver,&gmode,"");
printf("Enter the radius of circle: ");
scanf("%f",&r);
setbkcolor(WHITE);
setcolor(YELLOW);
xp=getmaxx()/2;yp=getmaxy()/2;
dt=1.0/r;
st=sin(dt*3.14/180);
ct=cos(dt*3.14/180);
x=0;y=r;
while(y>=x)
{
putpixel(xp+x,yp+y,RED);
putpixel(xp+x,yp-y,RED);
putpixel(xp-x,yp+y,RED);
putpixel(xp-x,yp-y,RED);
putpixel(xp+y,yp+x,RED);
putpixel(xp+y,yp-x,RED);
putpixel(xp-y,yp+x,RED);
putpixel(xp-y,yp-x,RED);
xt=x;
x=x*ct-y*st;
y=y*ct+xt*st;
delay(0);
}
getch();
closegraph();
}
OUTPUT:
PROGRAM:
#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
int xmin,xmax,ymin,ymax;
void main()
{
int gdriver=DETECT,gmode;
int x1,y1,x2,y2,x3,y3,count=0,x,x4,y4,code1[4],code2[4];
float t;
void codegen(int,int,int[]);
int retcode(int[]);
clrscr();
printf("\nEnter the clipping boundaries : \nXmin : ");
scanf("%d",&xmin);
printf("Xmax : ");
scanf("%d",&xmax);
printf("Ymin : ");
scanf("%d",&ymin);
printf("Ymax : ");
scanf("%d",&ymax);
printf("\nEnter the starting points : ");
scanf("%d%d",&x1,&y1);
printf("\nEnter the ending points : ");
scanf("%d%d",&x2,&y2);
codegen(x1,y1,code1);
codegen(x2,y2,code2);
x3=x1;y3=y1;x4=x2;y4=y2;
while((x=retcode(code1))!=4 && count<2)
{
switch(x)
{
case 0: y3=ymax;break;
case 1: y3=ymin;break;
case 2: x3=xmax;break;
case 3: x3=xmin;
}
if(x<2)
{
t=(y3-y1)/(float)(y2-y1);
x3=x1+t*(x2-x1);
}
else
{
t=(x3-x1)/(float)(x2-x1);
y3=y1+t*(y2-y1);
}
codegen(x3,y3,code1);
}
if(count<2)
{
while((x=retcode(code2))!=4 && count<4)
{
switch(x)
{
case 0: y4=ymax;break;
case 1: y4=ymin;break;
case 2: x4=xmax;break;
case 3: x4=xmin;
}
if(x<2)
{
t=(y4-y1)/(float)(y2-y1);
x4=x1+t*(x2-x1);
}
else
{
t=(x4-x1)/(float)(x2-x1);
y4=y1+t*(y2-y1);
}
count++;
codegen(x4,y4,code2);
}
if(count<4)
{
initgraph(&gdriver,&gmode,"");
line(x3,y3,x4,y4);
rectangle(xmin,ymax,xmax,ymin);
}
else
printf("\nThe line is completly outside ");
}
else
printf("\nThe line is completly outside ");
getch();
closegraph();
}
void codegen(int a,int b,int cod[])
{
cod[0]=(b<=ymax)?0:1;
cod[1]=(b<ymin)?1:0;
cod[2]=(a<=xmax)?0:1;
cod[3]=(a<xmin)?1:0;
}
int retcode(int cod[])
{
int i;
for(i=0;i<4;i++)
if(cod[i]==1)
break;
return i;
}
OUTPUT:
PROGRAM:
OUTPUT:
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void li(int,int,int,int,int,int);
void main() {
int gdrive=DETECT,gmode,menu,x,y,x5,y5,x1,x2,x3,x4,y1,y2,y3,y4,tx,ty;
float a;
initgraph(&gdrive,&gmode,"");
while(menu!=5) {
printf("\n1.Translation\n2.Rotation\n3.Scaling\n4.Reflection\n5.Exit");
printf("\nEnter your choice : ");
scanf("%d",&menu);
switch(menu) {
case 1:
printf("\nEnter first point:");
scanf("%d%d",&x1,&y1);
printf("Enter second point:");
scanf("%d%d",&x2,&y2);
printf("Enter third point:");
scanf("%d%d",&x,&y);
li(x1,x2,x,y1,y2,y);
printf("\nEnter Translation point:");
scanf("%d%d",&tx,&ty);
x3=x1+tx;y3=y1+ty;
x4=x2+tx;y4=y2+ty;
x5=x+tx;y5=y+ty;
setcolor(RED);
li(x3,x4,x5,y3,y4,y5);
break;
case 2:
printf("\nEnter first point:");
scanf("%d%d",&x1,&y1);
printf("Enter second point:");
scanf("%d%d",&x2,&y2);
printf("Enter third point:");
scanf("%d%d",&x,&y);
li(x1,x2,x,y1,y2,y);
printf("\nEnter angle:");
scanf("%f",&a);
a=a*3.14/180;
x3=x1*cos(a)-y1*sin(a);
y3=x1*sin(a)+y1*cos(a);
x4=x2*cos(a)-y2*sin(a);
y4=x2*sin(a)+y2*cos(a);
x5=x*cos(a)-y*sin(a);
y5=x*sin(a)+y*cos(a);
setcolor(RED);
li(x3,x4,x5,y3,y4,y5);
break;
case 3:
printf("\nEnter first point:");
scanf("%d%d",&x1,&y1);
printf("\nEnter second point:");
scanf("%d%d",&x2,&y2);
printf("Enter third point:");
scanf("%d%d",&x,&y);
li(x1,x2,x,y1,y2,y);
printf("Enter scaling factor:");
scanf("%d%d",&tx,&ty);
x3=x1*tx;y3=y1*ty;
x4=x2*tx;y4=y2*ty;
x5=x*tx;y5=y*ty;
setcolor(RED);
li(x3,x4,x5,y3,y4,y5);
break;
case 4:
line(getmaxx()/2,0,getmaxx()/2,getmaxy());
line(0,getmaxy()/2,getmaxx(),getmaxy()/2);
printf("\nEnter first point:");
scanf("%d%d",&x1,&y1);
printf("Enter second point:");
scanf("%d%d",&x2,&y2);
printf("Enter third point:");
scanf("%d%d",&x,&y);
li(x1+getmaxx()/2,x2+getmaxx()/2,x+getmaxx()/2,y1,y2,y);
li(x1,x2,x,y1,y2,y);
break;
case 5:
exit(0);
}
}
getch();
closegraph();
}
void li(int x1,int x2,int x,int y1,int y2,int y) {
line(x1,y1,x2,y2);
line(x2,y2,x,y);
line(x,y,x1,y1);
}
OUTPUT: