0% found this document useful (0 votes)
19 views

Cga Complete File All Pract

Uploaded by

zemsetanishka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Cga Complete File All Pract

Uploaded by

zemsetanishka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 45

Practical No: 1(A1)

Aim: To create Arc Function In C programming.


Code:

#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT, gm;
clrscr();
initgraph(&gd,&gm,"c:\\tc\\BGI");
arc(100,100,0,135,50);
getch();
closegraph();
}

Output:

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No: 1(A2)
Aim: Draw Polyfunction In C.

Code:

#include<graphics.h>

#include<conio.h>

void main()

int gd=DETECT,gm,points[]={320,150,420,300,250,300,320,150};

clrscr();

initgraph(&gd,&gm,"c:\\tc\\BGI");

drawpoly(4,points);

getch();

closegraph();

Output:

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No: 1(A3)
Aim: Draw line in C.

Code:

#include<graphics.h>

#include<graphics.h>

#include<conio.h>

void main()

int gd=DETECT,gm;

int xm=getmaxx(),ym=getmaxy();

initgraph(&gd,&gm,"c:\\tc\\BGI");

line(xm/2-100,ym/2-50,xm/2+100,ym/2+50);

getch();

}
Output:

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No: 1(A4)
Aim: Draw Rectangle In C.

Code:

#include<graphics.h>

#include<graphics.h>

#include<conio.h>

void main()

int gd=DETECT,gm;

int xm=getmaxx(),ym=getmaxy();

initgraph(&gd,&gm,"c:\\tc\\BGI");

rectangle(xm/2-100,ym/2-50,xm/2+100,ym/2+50);

getch();

OUTPUT:-

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No: 1(A6)
Aim: Closegraph Function in C.

Code:

#include<graphics.h>

#include<graphics.h>

#include<conio.h>

void main()

int gd=DETECT,gm;

clrscr();

initgraph(&gd,&gm,"c:\\tc\\BGI");

circle(100,100,50);

outtext("press any key to close the graphics mode:");

getch();

closegraph();

Output:

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No: 1(A5)
Name: Dipti Ashok Patil. Roll No. -53
Class-SYIT(B) Batch-2nd
Aim: Draw Circle In C.

Code:

#include<graphics.h>

#include<graphics.h>

#include<conio.h>

void main()

int gd=DETECT,gm;

clrscr();

initgraph(&gd,&gm,"c:\\tc\\BGI");

circle(100,100,50);

getch();

closegraph();

Output:

Practical No: 1(B)


Name: Dipti Ashok Patil. Roll No. -53
Class-SYIT(B) Batch-2nd
Aim: Floodfill Function In C.

Code:

#include<graphics.h>

#include<graphics.h>

#include<conio.h>

void main()

int gd=DETECT,gm;

initgraph(&gd,&gm,"c:\\tc\\BGI");

setcolor(RED);

circle(100,100,50);

floodfill(100,100,RED);

getch();

closegraph();

Output:

Practical No: 1(C)


Aim: Draw A Co-Ordinates At The Centre Of Screen.

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Code:

#include<graphics.h>

#include<graphics.h>

#include<conio.h>

void main()

int gd=DETECT,gm,xcen,ycen;

initgraph(&gd,&gm,"c:\\tc\\BGI");

xcen=getmaxx/2;

ycen=getmaxy/2;

line(xcen,0,xcen,getmaxy());

line(0,ycen,getmaxx(),ycen);

getch();

closegraph();

Output:

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Name: Dipti Ashok Patil. Roll No. -53
Class-SYIT(B) Batch-2nd
Practical No.-2A

Aim- Divide your screen in four region draw circle, rectangle, ellipse and sector
in each region with appropriate message.

Code-

#include<graphics.h>

#include<conio.h>

void main()

int gd=DETECT,gm,m,n,a,b;

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

m=getmaxx();

n=getmaxy();

a=m/2;

b=n/2;

line(m/2,0,m/2,n);

line(0,n/2,m,n/2);

circle(100,100,50);

outtextxy(80,170,"circle");

rectangle(a+50,b-150,a+150,b-30);\
Name: Dipti Ashok Patil. Roll No. -53
Class-SYIT(B) Batch-2nd
outtextxy(380,220,"Rectangle");

ellipse(155,340,0,360,130,40);

outtextxy(200,440,"ellipse");

sector(450,350,320,230,50,50);

outtextxy(450,440,"sector");

getch();

closegraph();

Output-

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No. -2B
Aim- Draw a simple hut on a screen using computer graphics.

Code-

#include<graphics.h>

#include<conio.h>

void main()

int gd=DETECT,gm,m,a,b,n;

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

setcolor(WHITE);

rectangle(150,180,250,300);

rectangle(250,180,420,300);

rectangle(180,250,220,300);

rectangle(280,250,320,280);

rectangle(350,250,390,280);

circle(200,150,10);

line(200,100,150,180);

line(200,100,250,180);

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
line(200,100,370,100);

line(370,100,420,180);

setfillstyle(SOLID_FILL,BROWN);

floodfill(152,182,WHITE);

floodfill(252,182,WHITE);

setfillstyle(SLASH_FILL,BLUE);

floodfill(182,152,WHITE);

setfillstyle(HATCH_FILL,GREEN);

floodfill(200,105,WHITE);

floodfill(210,105,WHITE);

setfillstyle(HATCH_FILL,YELLOW);

floodfill(282,252,WHITE);

setfillstyle(HATCH_FILL,YELLOW);

setfillstyle(SOLID_FILL,RED);

floodfill(202,152,WHITE);

getch();

closegraph();

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Output-

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No.-3A
Aim-Draw the following basic shapes in the center of the screen.

1. Circle, 2.Rectangle, 3.Ellipse, 4.Line.

Code-

#include<graphics.h>

#include<conio.h>

void main()

int gd=DETECT,gm,xcen,ycen;

clrscr();

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

xcen=getmaxx()/2;

ycen=getmaxy()/2;

line(xcen,0,xcen,getmaxy());

line(0,ycen,getmaxx(),ycen);

circle(xcen,ycen,200);

rectangle(xcen-200,ycen-200,xcen+200,ycen+200);

rectangle(xcen-120,ycen-180,xcen+120,ycen+180);

ellipse(xcen,ycen,0,360,50,100);

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
getch();

closegraph();

Output-

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No. - 3B
Aim- Draw the concentric circle in the center of the screen.

Code-

#include<graphics.h>

#include<conio.h>

#include<stdio.h>

#include<dos.h>

void main()

int gd=DETECT,gm,i,color=1,xcen,ycen;

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

xcen=getmaxx()/2;

ycen=getmaxy()/2;

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

setcolor(color++);

circle(xcen,ycen,i);

delay(50);

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
}

getch();

closegraph();

Output-

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No. -4A
Aim- Develop the program for DDA line drawing algorithm.

Code-

#include<graphics.h>

#include<conio.h>

#include<stdio.h>

#include<dos.h>

#include<math.h>

void main()

int gd=DETECT,gm,i;

float x,y,x1,y1,x2,y2,dx,dy,step;

initgraph(&gd,&gm,"C://TC//BGI");

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

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

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

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

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
dx=abs(x2-x1);

dy=abs(y2-y1);

if(dx>=dy)

step=dx;

else

step=dy;

dx=dx/step;

dy=dy/step;

x=x1;

y=y1;

i=1;

while(i<=step)

putpixel(x,y,5);

x=x+dx;

y=y+dy;

i=i+1;

delay(100);

getch();

closegraph();

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
}

Output-

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No. -4B
Aim- Develop the program for Bresenhams line drawing algorithm.

Code-

#include<graphics.h>

#include<conio.h>

#include<stdio.h>

void drawline(int x0,int y0, int x1, int y1)

int dx,dy,x,y,p;

dx=x1-x0;

dy=y1-y0;

x=x0;

y=y0;

p=2*dy-dx;

while(x<x1)

if(p>=0)

putpixel(x,y,7);//7 is time delay

y=y+1;

p=p+2*dy;

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
}

x=x+1;

void main()

int gdrive=DETECT,gmode,error,x0,y0,x1,y1;

initgraph(&gdrive,&gmode,"C://TC//BGI");

printf("Enter coordinate of first point");

scanf("%d%d",&x0,&y0);

printf("Enter coordinate of second point");

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

drawline(x0,y0,x1,y1);

getch();

closegraph();

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Output-

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No. -5
Aim- Develop the program for Midpoint Circle drawing algorithm.

Code-

#include<graphics.h>

#include<stdio.h>

#include<math.h>

#include<dos.h>

#include<conio.h>

void drawcircle(int x0,int y0,int r)

int x=r;

int y=0;

int err=0;

while(x>=y)

putpixel(x0+x,y0+y,7);

putpixel(x0+y,y0+x,5);

putpixel(x0-y,y0+x,8);

putpixel(x0-x,y0+y,2);

putpixel(x0-y,y0-x,12);

putpixel(x0-y,y0-x,14);

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
putpixel(x0+y,y0-x,9);

putpixel(x0+x,y0-y,6);

if(err<=0)

y=y+1;

err=err+2*y+1;

if(err>0)

x=x-1;

err=err-2*x+1;

void main()

int gd=DETECT,gm,err,x0,y0,r;

initgraph(&gd,&gm,"C://TC//BGI");

printf("Enter coordinate and radius");

scanf("%d%d",&x0,&y0,&r);

drawcircle(x0,y0,r);

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
getch();

closegraph();

Output-

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No. -8A
Aim- Develop a simple text screen saver using graphics function.

Code-
#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#include<dos.h>

#include<graphics.h>

void main()

int gd=DETECT,gm,col=480,row=640,font=4,direction=2,size=8,color=15;

initgraph(&gd,&gm,"C://TC//BGI");

cleardevice();

while(!kbhit())

settextstyle(random(font),random(direction),random(size));

setcolor(random(color));

outtextxy(random(col),random(row),"Welcome to Computer Graphics");

delay(100);

getch();

closegraph();

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Output-

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No. -8B
Aim- Perform smiling face animation using graphics function.

Code-

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#include<dos.h>

#include<graphics.h>

void main()

int gd=DETECT,gm,area,temp1,temp2,left=25,top=75,void*p;

initgraph(&gd,&gm,"C://TC//BGI");

setcolor(YELLOW);

circle(50,100,25);

setfillstyle(SOLID_FILL,YELLOW);

floodfill(50,100,YELLOW);

setcolor(BLACK);

setfillstyle(SOLID_FILL,BLACK);

fillellipse(44,84,2,6);

fillellipse(56,85,2,6);

ellipse(50,100,205,335,20,9);

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
ellipse(50,100,205,335,20,10);

ellipse(50,100,205,335,20,11);

area=imagesize(left,top,left+50,top+50);

p=malloc(area);

setcolor(WHITE);

settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);

outtextxy(155,451,"Smiling Face Animation");

setcolor(BLUE);

rectangle(0,0,639,449);

while(!kbhit())

temp1=1+random(588);

temp2=1+random(380);

getimage(left,top,left+50,top+50,p);

putimage(temp1,temp2,p,XOR_PUT);

putimage(temp1,temp2,p,XOR_PUT);

delay(500);

left=temp1;

top=temp2;

getch();

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
closegraph();

Output-

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No. -8C
Aim- Draw moving car on the screen.

Code-

#include<iostream.h>

#include<conio.h>

#include<graphics.h>

#include<dos.h>

void main()

clrscr();

int gd=DETECT,gm;

initgraph(&gd,&gm,"C:\\tc\\bgi");

for (int i=0;i<500;i++)

/***CAR BODY ******/

line(50+i,370,90+i,370);

arc(110+i,370,0,180,20);

line(130+i,370,220+i,370);

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
arc(240+i,370,0,180,20);

line(260+i,370,300+i,370);

line(300+i,370,300+i,350);

line(300+i,350,240+i,330);

line(240+i,330,200+i,300);

line(200+i,300,110+i,300);

line(110+i,300,80+i,330);

line(80+i,330,50+i,340);

line(50+i,340,50+i,370);

/***CAR Windows***/

line(165+i,305,165+i,330);

line(165+i,330,230+i,330);

line(230+i,330,195+i,305);

line(195+i,305,165+i,305);

line(160+i,305,160+i,330);

line(160+i,330,95+i,330);

line(95+i,330,120+i,305);

line(120+i,305,160+i,305);

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
/**Wheels**/

circle(110+i,370,17);

circle(240+i,370,17);

delay(10);

cleardevice();

line(0,390,639,390); //ROAD

getch();

Output-

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No. -6A
Aim- To perform translation transformation on a given triangle.

Code-

#include<iostream.h>

#include<conio.h>

#include<graphics.h>

#include<dos.h>

void main()

int gd=DETECT,gm,x1=100,y1=100,x2=80,y2=150,x3=120,y3=150,tx,ty;

initgraph(&gd,&gm,"C://TC//BGI");

line(x1,y1,x2,y2);

line(x2,y2,x3,y3);

line(x3,y3,x1,y1);

cout<<"Translation of value for x Co-ordinate";

cin>>tx;

cout<<"Translation of value for y Co-ordinate";

cin>>ty;

x1+=tx;x2+=tx;x3+=tx;

y1+=ty;y2+=ty;y3+=ty;

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
line(x1,y1,x2,y2);

line(x2,y2,x3,y3);

line(x3,y3,x1,y1);

getch();

closegraph();

Output-

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No. -6B
Aim- To perform scaling transformation on a given triangle.

Code-

#include<iostream.h>

#include<conio.h>

#include<graphics.h>

void main()

clrscr();

int gd=DETECT,gm,x1=100,y1=100,x2=80,y2=150,x3=120,y3=150,sx,sy;

initgraph(&gd,&gm,"C://TC//BGI");

line(x1,y1,x2,y2);

line(x2,y2,x3,y3);

line(x3,y3,x1,y1);

cout<<"Enter scaling value among x-axis";

cin>>sx;

cout<<"Enter scaling value among y-axis";

cin>>sy;

x1*=sx;x2*=sx;x3*=sx;

y1*=sy;y2*=sy;y3*=sy;

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
line(x1,y1,x2,y2);

line(x2,y2,x3,y3);

line(x3,y3,x1,y1);

getch();

closegraph();

Output-

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No. -6C
Aim- To perform rotation transformation on a given triangle.

Code-

#include<iostream.h>

#include<conio.h>

#include<graphics.h>

#includ<math.h>

void main()

clrscr();

int gd=DETECT,gm,x1=200,y1=200,x2=180,y2=250,x3=220,y3=250;

float angle;

initgraph(&gd,&gm,"C://TC//BGI");

line(x1,y1,x2,y2);

line(x2,y2,x3,y3);

line(x3,y3,x1,y1);

cout<<"Enter rotation angle";

cin>>angle;

angle=angle*3.1428/180;

x1=x1*cos(angle)-y1*sin(angle);

y1=(x1*sin(angle))+y1*cos(angle);

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
x2=x2*cos(angle)-y2*sin(angle);

y2=(x2*sin(angle))+y2*cos(angle);

x3=x3*cos(angle)-y3*sin(angle);

y3=(x3*sin(angle))+y3*cos(angle);

line(x1,y1,x2,y2);

line(x2,y2,x3,y3);

line(x3,y3,x1,y1);

getch();

closegraph();

Output-

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Practical No. -7
Aim- To perform reflection of point about a line Y=MX+C.

Code-

#include<iostream.h>

#include<conio.h>

#include<graphics.h>

void main()

clrscr();

int gd=DETECT,gm;

initgraph(&gd,&gm,"C://TC//BGI");

int x1,y1,x2,y2;

cout<<"Enter the co-ordinate of line";

cin>>x1>>y1>>x2>>y2;

int m=getmaxx();

int n=getmaxy();

setcolor(6);

line(x1,y1,x2,y2);

outtextxy(x1,y1+10,"original object");

setcolor(4);

line((m/2),0,(m/2),n);

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
line(0,(n/2),m,(n/2));

setcolor(3);

int c=(n/2)-y1;

int d=(n/2)-y2;

y2=y2+(d*2);

y1=y1+(c*2);

line(x2,y2,x1,y1);

outtextxy(x1,y1+10,"Reflection among x axis");

setcolor(9);

int a=(m/2)-x1;

int b=(n/2)-x2;

x1=x1+(a*2);

x2=x2+(b*2);

line(x1,y1,x2,y2);

outtextxy(x2-20,y2+10,"Reflection along y axis");

getch();

closegraph();

Output-

Name: Dipti Ashok Patil. Roll No. -53


Class-SYIT(B) Batch-2nd
Name: Dipti Ashok Patil. Roll No. -53
Class-SYIT(B) Batch-2nd

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy