Facebook
From cga prac, 1 Month ago, written in Plain Text.
This paste is a reply to exam from cga - go back
Embed
Viewing differences between exam and Re: exam
1)draw coordinate axis at centre of screen
#include
#include
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm,xcen,ycen;
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
xcen=getmaxx()/2;
ycen=getmaxy()/2;
line(xcen,0,xcen,getmaxy());
line(0,ycen,getmaxx(),ycen);
getch();
closegraph();
}

2)
a. Develop the program for DDA Line drawing algorithm.
CODE:
#include
#include
#include
#include
#include
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
void main()
{
int gd=DETECT,gm;
float x1,y1,x2,y2,i,dx,dy,m;
printf("\nEnter printf("\nEnter the x1 and y1 coordinate: ");
scanf("%f%f",&x1;,&y1;);
printf("\nEnter 
");
scanf("%f%f",&x1;,&y1;);
printf("\nEnter 
the x2 and y2 coordinate: ");
scanf("%f%f",&x2;,&y2;);
");
scanf("%f%f",&x2;,&y2;);
m=(y2-y1)/(x2-x1);
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
for(i=x1;i<=x2;i++)
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
for(i=x1;i<=x2;i++)
{
if(m<1)
if(m<1)
{
dx=x1+1;
dy=y1+m;
}
else if(m>1)
if(m>1)
{

}
else
{

}
dx=x1+(1/m);
dy=y1+1;

dx=x1+1;
dy=y1+1;

abs(dx);
abs(dy);
putpixel(dx,dy,15);
x1=dx;
y1=dy;
delay(50);
}
outtextxy(x2,y2,"DDA LINE");
outtextxy(x2,y2,"DDA LINE");
getch();
closegraph();}

3)
5A WRITE A PROGRAM TO IMPLEMENT 2D SCALING
A1 WRITE A PROGRAM TO SCALE 2D LINE
CODE:
#include
#include
#include
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void main()
{
float x1,x2,y1,y2,sx,sy;
int gd=DETECT,gm;
printf("\nEnter printf("\nEnter Start Cooridinate (x1,y1): ");
scanf("%f%f",&x1;,&y1;);
printf("\nEnter 
");
scanf("%f%f",&x1;,&y1;);
printf("\nEnter 
the End Cooridinate(x2,y2): ");
scanf("%f%f",&x2;,&y2;);

printf("'\nEnter 
");
scanf("%f%f",&x2;,&y2;);

printf("'\nEnter 
Scaling Parmeters: ");
scanf("%f%f",&sx;,&sy;);
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
");
scanf("%f%f",&sx;,&sy;);
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
line(x1,y2,x2,y2);
outtextxy(x1,y1,"Line outtextxy(x1,y1,"Line Before Scaling");
Scaling");
x1=x1*sx;
y1=y1*sy;
x2=x2*sx;
y2=y2*sy;
line(x1,y1,x2,y2);
outtextxy(x1,y1,"Line outtextxy(x1,y1,"Line After Scaling");
Scaling");
getch();
closegraph();
}

4)
A)Develop a simple text screen saver using graphics functions.
#include 
<stdio.h>
#include 
<stdlib.h>
#include 
<graphics.h>
#include 
<conio.h>
#include 
<dos.h>
void main()
{
int
gdriver=DETECT,gmode,col=480,row=640,font=4,direction=2,size=8,col
or=15;
initgraph(&gdriver;,&gmode;,"C:\\TurboC3\\BGI");
initgraph(&gdriver;,&gmode;,"C:\\TurboC3\\BGI");
cleardevice();
while(!kbhit()){
settextstyle(random(font),random(direction),random(size));
setcolor(random(color));
outtextxy(random(col),random(row),"Komal");
outtextxy(random(col),random(row),"Komal");
delay(250);
}
closegraph();
}

5)
B. Draw a simple hut on the screen.

CODE:
#include
#include
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT, gm;
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
rectangle(150,180,250,300);
rectangle(250,180,420,300);
rectangle(180,250,220,300);
line(200,100,150,180);
line(200,100,250,180);
line(200,100,370,100);
line(370,100,420,180);
getch();
closegraph();
}

6)
A. Divide your screen into four region, draw circle, rectangle, ellipse and
half ellipse in each region

CODE:
#include
#include
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm,xcen,ycen;
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
xcen=getmaxx()/2;
ycen=getmaxy()/2;
line(xcen,0,xcen,getmaxy());
line(0,ycen,getmaxx(),ycen);
rectangle(xcen+50,ycen-200,xcen+200,ycen-50);
ellipse(xcen-xcen/2,ycen+ycen/2,0,360,100,50);
ellipse(xcen+xcen/2,ycen+ycen/2,0,180,100,50);
getch();
closegraph();
}
7)
B) Perform smiling face animation using graphic functions.
#include
#include
#include
#include
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
void main()
{
int gd=DETECT,gm,x=250,y=250;
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
cleardevice();
while(!kbhit())
{
setfillstyle(SOLID_FILL,14);
fillellipse(x,y,100,100);
setfillstyle(SOLID_FILL,random(6));
fillellipse(x-30,y-30,20,40);
fillellipse(x+30,y-30,20,40);
setcolor(random(3));
ellipse(x,y+10,180,0,60,50);
delay(500);
}
closegraph();
}

8)
5B: WRITE A PROGRAM TO IMPLEMENT 2D Translation
B1 WRITE A PROGRAM TO IMPLEMENT 2D Translation on a line
CODE:
#include
#include
#include
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
float Tx,Ty,x1,y1,x2,y2;
printf("Enterthe coordinates(x1,y1):");

SYIT CGA Practical

Komal Jambhale 6
scanf("%f%f",&x1;,&y1;);
printf("Enterthe 
printf("Enterthe coordinates(x1,y1):");
scanf("%f%f",&x1;,&y1;);
printf("Enterthe 
second coordinations(x1,y2)");
scanf("%f%f",&x2;,&y2;);
printf("Enterthe 
coordinations(x1,y2)");
scanf("%f%f",&x2;,&y2;);
printf("Enterthe 
translation parameter(Tx,Ty)");
scanf("%f%f",&Tx;,&Ty;);
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
parameter(Tx,Ty)");
scanf("%f%f",&Tx;,&Ty;);
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
line(x1,y1,x2,y2);
outtextxy(x1,y1,"Before Translation");
outtextxy(x1,y1,"Before Translation");
x1=x1+Tx;
y1=y1+Ty;
x2=y2+Tx;
y2=y2+Ty;
line(x1,y1,x2,y2);
outtextxy(x2,y2,"After Translation");
outtextxy(x2,y2,"After Translation");
getch();
closegraph();
}