#include
#include<conio.h>
void main()
{
int gd=DETECT,gm,xcen,ycen;
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<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;
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);
for(i=x1;i<=x2;i++)
for(i=x1;i<=x2;i++)
{
{
dx=x1+1;
dy=y1+m;
}
else
{
}
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);
}
getch();
closegraph();}
3)
5A WRITE A PROGRAM TO IMPLEMENT 2D SCALING
A1 WRITE A PROGRAM TO SCALE 2D LINE
CODE:
#include
#include
#include<stdio.h>
#include<graphics.h>
void main()
{
float x1,x2,y1,y2,sx,sy;
int gd=DETECT,gm;
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);
x1=x1*sx;
y1=y1*sy;
x2=x2*sx;
y2=y2*sy;
line(x1,y1,x2,y2);
getch();
closegraph();
}
4)
A)Develop a simple text screen saver using graphics functions.
#include
#include
#include
#include
#include
void main()
{
int
gdriver=DETECT,gmode,col=480,row=640,font=4,direction=2,size=8,col
or=15;
cleardevice();
while(!kbhit()){
settextstyle(random(font),random(direction),random(size));
setcolor(random(color));
delay(250);
}
closegraph();
}
5)
B. Draw a simple hut on the screen.
CODE:
#include
#include<conio.h>
void main()
{
int gd=DETECT, gm;
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<conio.h>
void main()
{
int gd=DETECT,gm,xcen,ycen;
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<conio.h>
#include<graphics.h>
#include<stdlib.h>
void main()
{
int gd=DETECT,gm,x=250,y=250;
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<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
float Tx,Ty,x1,y1,x2,y2;
SYIT CGA Practical
Komal Jambhale 6
scanf("%f%f",&x1;,&y1;);
printf("Enterthe
scanf("%f%f",&x1;,&y1;);
printf("Enterthe second
scanf("%f%f",&x2;,&y2;);
printf("Enterthe
scanf("%f%f",&x2;,&y2;);
printf("Enterthe translation
scanf("%f%f",&Tx;,&Ty;);
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
scanf("%f%f",&Tx;,&Ty;);
initgraph(&gd;,&gm;,"C:\\TC\\BGI");
line(x1,y1,x2,y2);
x1=x1+Tx;
y1=y1+Ty;
x2=y2+Tx;
y2=y2+Ty;
line(x1,y1,x2,y2);
getch();
closegraph();
}