0% found this document useful (0 votes)
41 views35 pages

Pranav ACG

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 35

Expriment No:2

Title:- Draw a Circle,Arc,Ellipse & Rectangle.

Name:- Pranav d. Koli

Roll No:-26 Batch:-S2

#include<graphics.h>

#include<stdio.h>

#include<conio.h> void

main()

int gd=DETECT,gm;

initgraph(&gd,&gm,"C:\\TurboC3\\BGI");

printf("\t\t\t\n\nLINE"); line(50,40,190,40);

printf("\t\t\n\n\n\nRECTANGLE");

rectangle(125,115,215,165);

printf("\t\t\t\n\n\n\n\n\nARC");

arc(120,200,180,0,30);

printf("\t\n\n\n\nCIRCLE");

circle(120,270,30);
printf("\t\n\n\nELLIPSE");

ellipse(120,350,0,360,30,20) ; getch();

closegraph();

//output

Expriment No:3
Title:- 2D Translation,Rotation and Scaling.
Name:- Pranav d. Koli

Roll No:-26 Batch:-S2

//2D translation

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<process.h>

#include<math.h> int x1, y1, x2,

y2, x3, y3, mx, my; void draw();

void tri();

void main()

int gd = DETECT, gm;

int c;

initgraph(&gd, &gm, "C:\\TurboC3\\BGI");

printf("Enter the 1st point for the triangle: "); scanf("%d%d",

&x1, &y1);

printf("\nEnter the 2nd point for the triangle: ");

scanf("%d%d", &x2, &y2);

printf("\nEnter the 3rd point for the triangle: ");

scanf("%d%d", &x3, &y3);

cleardevice();
draw();

getch(); tri();

getch();

void draw()

line(x1, y1, x2, y2);

line(x2, y2, x3, y3); line(x3,

y3, x1, y1);

} void

tri()

int x, y, a1, a2, a3, b1, b2, b3;

printf("\nEnter the transition coordinates: ");

scanf("%d%d", &x, &y); cleardevice(); a1 =

x1 + x; b1 = y1 + y; a2 = x2 + x; b2 = y2 + y;

a3 = x3 + x; b3 = y3 + y;

line(a1, b1, a2, b2);

line(a2, b2, a3, b3); line(a3, b3,

a1, b1);

OUTPUT:
//2D Rotation
#include<stdio.h>

#include<graphics.h>

#include<math.h>

void main() {

int gd = DETECT, gm, r, d, x1, y1, x2, y2, xn1, yn1, xn2, yn2;

float ra, si, co;


initgraph(&gd, &gm, "C:\\TurboC3\\BGI");

printf("Enter the value of x1 and y1: ");

scanf("%d%d", &x1, &y1);

printf("Enter the value of x2 and y2: ");

scanf("%d%d", &x2, &y2);

line(x1, y1, x2, y2); printf("Enter

the degree of rotation: ");

scanf("%d", &d);

//starting point would be the same

xn1 = x1;

yn1 = y1;

//convert degree into radius

r = x2-x1;

ra = 0.0175 *

d; si = sin(ra);

co = cos(ra);

//second point

xn2 = x1 + r * co + 1;

yn2 = y1 + r * si + 1;

line(xn1, yn1, xn2, yn2);

getch();
closegraph();

OUTPUT:

//2D Scaling

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<process.h>

#include<math.h> int

x1,y1,x2,y2,x3,y3,mx,my;

void draw(); void scale();

void main()

int gd=DETECT,gm;

int c;

initgraph(&gd,&gm,"..\\bgi");

printf("Enter the 1st point for the triangle:");


scanf("%d%d",&x1,&y1);

printf("Enter the 2nd point for the triangle:");

scanf("%d%d",&x2,&y2);

printf("Enter the 3rd point for the triangle:");

scanf("%d%d",&x3,&y3);

draw(); scale();

} void draw() {

line(x1,y1,x2,y2);

line(x2,y2,x3,y3);

line(x3,y3,x1,y1);

} void scale() { int

x,y,a1,a2,a3,b1,b2,b3; int mx,my;

printf("Enter the scalling coordinates");

scanf("%d%d",&x,&y);

mx=(x1+x2+x3)/3; my=(y1+y2+y3)/3;

cleardevice();

a1=mx+(x1-mx)*x; b1=my+(y1-

my)*y; a2=mx+(x2-mx)*x;

b2=my+(y2-my)*y; a3=mx+(x3-

mx)*x; b3=my+(y3-my)*y;

line(a1,b1,a2,b2);

line(a2,b2,a3,b3);

line(a3,b3,a1,b1);

draw(); getch();
}

Output
Expriment No:4
Title:- Draw a Circle,Arc,Ellipse & Rectangle.

Name:- Pranav d. Koli

Roll No:-26 Batch:-S2

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<math.h> int

maxx,maxy,midx,midy;

void axis()

getch();

cleardevice();

line(midx,0,midx,maxy) ;

line(0,midy,maxx,midy);

} void

main()

int gd,gm,x,y,z,ang,x1,x2,y1,y2;

detectgraph(&gd,&gm);

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

setfillstyle(3,25);
maxx=getmaxx();

maxy=getmaxy(); midx=maxx/2;

midy=maxy/2;

outtextxy(100,100,"ORIGINAL OBJECT");

line(midx,0,midx,maxy); line(0,midy,maxx,midy);

bar3d(midx+100,midy-20,midx+60,midy-90,20,5);

axis();

outtextxy(100,20,"TRANSLATION");

printf("\n\n Enter the translation vector:");

scanf("%d%d",&x,&y);

bar3d(midx+100,midy-20,midx+60,midy-90,20,5); bar3d(midx+(x+100),midy-

(y+20),midx+(x+60),midy-(y+90),20,5);

axis();

outtextxy(100,20,"SCALING");

printf("\n\n Enter the scaling vector:");

scanf("%d%d%d",&x,&y,&z);

bar3d(midx+100,midy-20,midx+60,midy-90,20,5); bar3d(midx+(x*100),midy-

(y*20),midx+(x*60),midy-(y*90),20*z,5);

axis();

outtextxy(100,20,"ROTATION");

printf("\n\n Enter the Rotation angle:");

scanf("%d",&ang);
x1=100*cos(ang*3.14/180)-20*sin(ang*3.14/180);

y1=100*sin(ang*3.14/180)+20*sin(ang*3.14/180);

x2=60*cos(ang*3.14/180)-90*sin(ang*3.14/180);

y2=60*sin(ang*3.14/180)+90*sin(ang*3.14/180);

axis();

printf("\n After rotation about z-axis \n");

bar3d(midx+100,midy-20,midx+60,midy-90,20,5);

bar3d(midx+x1,midy-y1,midx+x2,midy-y2,20,5);

axis();

printf("\n After rotation about x-axis \n");

bar3d(midx+100,midy-20,midx+60,midy-90,20,5); bar3d(midx+100,midy-

x1,midx+60,midy-x2,20,5);

axis();

printf("\n After rotation about y-axis \n");

bar3d(midx+100,midy-20,midx+60,midy-90,20,5);

bar3d(midx+x1,midy-20,midx+x2,midy-90,20,5);

axis();

closegraph();

}
Output
Expriment No:5
Title:- Bresenham’s line drawing algorithm.

Name:- Pranav d. Koli

Roll No:-26 Batch:-S2

#include<stdio.h>

#include<conio.h>

#include<graphics.h> int

main()

int gd,gm,x,y,end,p,x1,x2,y1,y2,dx,dy;

detectgraph(&gd,&gm) ;

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

printf("Enter the value of x1:");

scanf("%d",&x1);

printf("Enter the value of y1:");

scanf("%d",&y1);

printf("Enter the value of x2:");

scanf("%d",&x2);

printf("Enter the value of y2:");

sacnf("%d",&y2) ;
dx=abs(x1-x2);

dy=abs(y1-y2); p=2*dy=dx;

if(x1>x2)

x=x2;

y=y2;

end=x1;

else

x=x1;

y=y1;

end=x2;

putpixel(x,y,WHITE) ;

while(x<=end)

if(p<0)

x++;

p=p+2*dy;

else
{

x++;

y++;

p=p+2*(dy-dx);

putpixel(x,y,WHITE);

delay(100);

getch();

closegraph(); return 0;

Output

Expriment No:6
Title:- Bresenham’s Circle drawing algorithm.

Name:- Pranav d. Koli

Roll No:-26 Batch:-S2

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<stdlib.h>

#include<math.h>

void EightWaySymmetricPlot(int xc,int yc ,int x,int y)

putpixel(x+xc,y+yc,RED); putpixel(x+xc,-

y+yc,YELLOW); putpixel(-x+xc,-y+yc,GREEN);

putpixel(-x+xc,y+yc,YELLOW);

putpixel(y+xc,x+yc,12); putpixel(y+xc,-x+yc,14);

putpixel(-y+xc,-x+yc,15); putpixel(-

y+xc,x+yc,6);

void BresenhamCricle(int xc,int yc,int r)

int x=0,y=r,d=3-(2*r);

EightWaySymmetricPlot(xc,yc,x,y); while(x<=y)
{ if(d<=0)

d=d+(4*x)+6;

} else

d=d+(4*x)-(4*y)+10;

y=y-1;

x=x+1;

EightWaySymmetricPlot(xc,yc,x,y);

} } int

main(void)

int xc,yc,r,gdrive=DETECT,gmode,errorcode;

initgraph(&gdrive,&gmode,"c:\\turboc3\\bgi");

errorcode=graphresult();

if(errorcode!=grOk)

printf("Graphics error:%s\n",grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

exit(1);

}
printf("Enter the value of xc and yc:");

scanf("%d%d",&xc,&yc);

printf("enterv the value of radius:") ;

scanf("%d",&r) ;

BresenhamCricle(xc,yc,r) ;

getch();

closegraph(); return 0;

Output

Expriment No:7
Title:- Mid-Point circle drawing algorithm.

Name:- Pranav d. Koli

Roll No:-26 Batch:-S2

#include<stdio.h>
#include<conio.h>

#include<graphics.h> int

main()

int gd=DETECT,gm;

int x,y,r;

void Drawcircle(int,int,int);

printf("Enter the mid point and radius :");

scanf("%d%d%D",&x,&y,&r) ;

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

Drawcircle(x,y,r);

getch();

closegraph();

} void Drawcircle(int x1,int y1,int

r)

int x=0,y=r,p=1-r ;

void cliplot(int,int,int,int);

cliplot(x1,y1,x,y);

while(x<y)

x++;

if(p<0)

p+=2*x+1;
else

y--;

p+=2*(x-y)+1 ;

cliplot(x1,y1,x,y);

} void cliplot(int xctr,int yctr,int x,int

y)

putpixel(xctr+x,yctr+y,1); putpixel(xctr-

x,yctr+y,1); putpixel(xctr+x,yctr-y,1); putpixel(xctr-

x,yctr-y,1); putpixel(xctr+y,yctr+x,1); putpixel(xctr-

y,yctr+x,1); putpixel(xctr+y,yctr-x,1); putpixel(xctr-

y,yctr-x,1);

getch();

}
Output
Expriment No:8
Title:-Polygon Filling.

Name:- Pranav d. Koli

Roll No:-26 Batch:-S2

#include<conio.h>

#include<stdio.h>

#include<graphics.h>

#include<math.h>

#include<dos.h>

#include<process.h> void

main()

int p=1,i,j,d,x; int

a[12]={100,100,150,150,200,100,200,200,100,200,100,100};

int gd=DETECT,gm;

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

drawpoly(6,a);

for(i=100;i<200;i++)

p=1;

for( j=100;j<200;j++)

x=getpixel(j,i);

for(d=0;d<11;d++)
{

if(x>0&&d==10)

p++;

if(p%2==0)
putpixel(j,i,4) ;

}
}

getch(); closegraph();

Output

Expriment No:9
Title:- Line Clipping.
Name:- Pranav d. Koli

Roll No:-26 Batch:-S2

#include<stdio.h>

#include<conio.h>

#include<graphics.h> #include<dos.h>

void storepoints(int,int,int,int,int,int,int[]);

void main()

int gdrive=DETECT,gmode;

int x1,x2,y1,y2,xmax,ymax,xmin,ymin,a[10],b[20],xi1,xi2,yi1,yi2,flag=0;

float m;

int i; clrscr();

printf("output");

printf("\n");

printf("enter the value of x1,y1,x2,y2:>");

scanf("%d%d%d%d",&x1,&y1,&x2,&y2);

printf("enter the value of xmax,ymax,xmin,ymin");

scanf("%d%d%d%d",&xmax,&ymax,&xmin,&ymin);

storepoints(x2,y2,ymin,ymax,xmax,xmin,b) ;

for(i=1;i<=4;i++)

if(a[i]*b[i]==0)

flag=1;

else
flag=0;

if(flag==1)

m=(y2-y1)/(x2-x1);

xi1=x1;

yi1=y1;

if(a[1]==1)

yi1=ymax;

xi1=x1+((1/m)*(yi1-y1));

else

if(a[2]==1)

yi1=ymin;

xi1=x1+((1/m)*(yi1-y1));

if(a[3]==1)
{

xi1=xmax;

yi1=y1+(m*(xi1-x1));

if(a[4]==1)

xi1=xmin;

yi1=y1+(m*(xi1-x1));

else

if(b[1]==1)

yi2=ymax;

xi2=x2+((1/m)*(yi2-y2));

else

if(b[2]==1)

yi2=ymin;

xi2=x2+((1/m)*(yi2-y2));

else

if(a[3]==1)

{
xi2=xmax;

yi2=y2+((1/m)*(xi2-x2));

else

if(a[4]==1)

xi2=xmin;

yi2=y2+(m*(xi2-x2));

clrscr();

initgraph(&gdrive,&gmode,"c://turboc3//bgi");

line(xi1,yi1,xi2,xi2); rectangle(xmin,ymin,xmax,ymax);

delay(5000);

if(flag==0)

printf("\n no clipping is required") ;

getch();

closegraph();

} void storepoints(int x1,int y1,int ymax,int xmax,int xmin,int ymin,int

c[10])

if((y1-ymax)>0)

c[1]=1;
else

c[1]=0;

if((ymin-y1)>0)

c[2]=1;

else

c[2]=0 ; if((x1-

xmax)>0)

c[3]=1;

else

c[3]=0;

if((xmin-x1)>0)

c[4]=1;

else

c[4]=0;

Output
Expriment No:11
Title:- Draw a Circle,Arc,Ellipse & Rectangle.

Name:- Pranav d. Koli

Roll No:-26 Batch:-S2

#include<stdio.h>

#include<conio.h>

#include<graphics.h> void

main()

{ int

x,y,x1,x2,y1,y2,k,dx,dy,s,xi,yi;

int gdriver=DETECT,gmode;

clrscr();

initgraph(&gdriver,&gmode,"C://TURBOC3//BGI");

printf("enter first point:");

scanf("%d%d",&x1,&y1);

printf("enter second point:");

scanf("%d%d",&x2,&y2);

x=x1; y=y1;

putpixel(x,y,7);

dx=x2-x1; dy=y2-

y1;

if(abs(dx)>abs(dy))

s=abs(dx);

else
s=abs(dy);

xi=dx/s; yi=dy/s;

x=x1; y=y1;

putpixel(x,y,7);

for(k=0;k<s;k++)

x=x+xi;

y=y+yi;

putpixel(x,y,7);

getch();

closegraph();

OUTPUT:

You might also like