M.sc. Computer Science - Software Engineering
M.sc. Computer Science - Software Engineering
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,poly[12];
initgraph(&gd,&gm,"c:\\TURBOC3\\BGI");
outtextxy(100,350.”SHAPES USING OUTPUT PRIMITIVES”);
outtextxy(30,30,"line");
line(10,50,100,50);
outtextxy(150,30,"rectangle");
rectangle(130,50,250,130);
outtextxy(300,30,"circle");
circle(330,100,50);
outtextxy(480,30,"Arc");
arc(500,150,400,500,100);
outtextxy(30,170,"Ellipse");
ellipse(50,250,0,360,30,50);
outtextxy(150,170,"bar");
bar3d(130,200,180,300,15,1);
outtextxy(250,170,"Pieslice");
pieslice(300,300,45,135,100);
outtextxy(400,170,"Polygon");
poly[0]=460;
poly[1]=180;
poly[2]=500;
poly[3]=220;
poly[4]=480;
poly[5]=280;
poly[6]=440;
poly[7]=280;
poly[8]=420;
poly[9]=220;
poly[10]=460;
poly[11]=180;
drawpoly(6,poly);
getch();
closegraph();
}
OUTPUT
2.DIGITAL DIFFERENTIAL ANALYZER (DDA) ALGORITHM
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void main()
{
float x1, y1, x2, y2, m, x, y, i;
int gd=DETECT, gm, xr, yr;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
printf(“\n\tDDA ALGORITHM”);
printf(“\n\t-----------------------“);
printf("Enter x1 and y1 : ");
scanf("%f %f", &x1, &y1);
printf("Enter x2 and y2 : ");
scanf("%f %f", &x2, &y2);
m=(y2-y1)/(x2-x1);
x=x1;
y=y1;
putpixel(x,y,7);
if(m<1)
{
for(i=x1; i<x2; i++)
{
x++;
y+=m;
yr=(int)(y+0.5);
putpixel(x,yr,7);
}
}
else
{
for(i=y1; i<y2; i++)
{
x+=(1/m);
xr=(int)(x+0.5);
y++;
putpixel(xr,y,7);
}
}
getch();
closegraph();
}
OUTPUT
3.BRESENHAM'S LINE DRAWING ALGORITHM
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void drawline(int x1, int y1, int x2, int y2)
{
int dx, dy, p, x, y;
float m;
dx=x2-x1;
dy=y2-y1;
x=x1;
y=y1;
p=2*dy-dx;
m=dy/dx;
if(m<1)
{
while(x<=x2)
{
if(p>=0)
{
putpixel(x,y,7);
y=y+1;
p=p+2*dy-2*dx;
}
else
{
putpixel(x,y,7);
p=p+2*dy;
}
x=x+1;
}
}
else
{
while(y<=y2)
{
if(p>=0)
{
putpixel(x,y,7);
x=x+1;
p=p+2*dx-2*dy;
}
else
{
putpixel(x,y,7);
p=p+2*dx;
}
y=y+1;
}
}
}
void main()
{
int x1, y1, x2, y2, gd=DETECT, gm;
initgraph(&gd,&gm,"c:\\TURBO3\\BGI");
printf(“\n\t BRESENHAM LINE DRAWING ALGORITHM”);
prinft(“\n\t-----------------------------------------------------------“);
printf("Enter the co-ordinates of first point : ");
scanf("%d %d", &x1,&y1);
printf("Enter the co-ordinates of second point : ");
scanf("%d %d", &x2,&y2);
drawline(x1,y1,x2,y2);
getch();
closegraph();
}
OUTPUT
4.MID-POINT CIRCLE DRAWING ALGORITHM
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void drawcircle(int x1, int y1, int radius)
{
int x=radius;
int y=0;
int p=0;
while(x>=y)
{
putpixel(x1+x, y1+y, 7);
putpixel(x1+x, y1-y, 7);
if(p<=0)
{
y=y+1;
p=p+2*y+1;
}
if(p>0)
{
x=x-1;
p=p-2*x+1;
}
}
}
void main()
{
int gd=DETECT, gm, x, y, r;
initgraph(&gd, &gm, "c:\\TURBOC3\\BGI");
printf("Enter the Radius of the Circle : ");
scanf("%d", &r);
printf("Enter the Co-ordinates of center : ");
scanf("%d %d", &x, &y);
drawcircle(x,y,r);
getch();
closegraph();
}
OUTPUT
5.COHEN–SUTHERLAND LINE CLIPPING
#include"stdio.h"
#include"conio.h"
#include"graphics.h"
void main()
{
int gd=DETECT, gm;
float i,xmax,ymax,xmin,ymin,x1,y1,x2,y2,m;
float start[4],end[4],code[4];
clrscr();
initgraph(&gd,&gm,"c:\\TURBOC3\\BGI");
printf("\n\t\t\t LINE CLIPPING ");
printf("\n\t\t\t---------------\n");
printf("\n\tEnter the bottom left co-ordinate of viewport: ");
scanf("%f %f",&xmin,&ymin);
printf("\n\tEnter the top right co-ordinate of viewport : ");
scanf("%f %f",&xmax,&ymax);
printf("\n\nEnter the co-ordinates for starting point of line : ");
scanf("%f %f",&x1,&y1);
printf("\nEnter the co-ordinates for ending point of line : ");
scanf("%f %f",&x2,&y2);
for(i=0;i <4;i++)
{
start[i]=0;
end[i]=0;
}
m=(y2-y1)/(x2-x1);
if(x1 <xmin) start[0]=1;
if(x1 >xmax) start[1]=1;
if(y1 >ymax) start[2]=1;
if(y1 <ymin) start[3]=1;
if(x2 <xmin) end[0]=1;
if(x2 >xmax) end[1]=1;
if(y2 >ymax) end[2]=1;
if(y2 <ymin) end[3]=1;
for(i=0;i <4;i++)
code[i]=start[i]&&end[i];
if((code[0]==0)&&(code[1]==0)&&(code[2]==0)&&(code[3]==0))
{
if((start[0]==0)&&(start[1]==0)&&(start[2]==0)&&(start[3]==0)&&(end[0]==0)&&(en
d[1]==0)&&(end[2]==0)&&(end[3]==0))
{
cleardevice();
printf("\n\t\tThe line is totally visible\n\t\tand not a clipping candidate");
rectangle(xmin,ymin,xmax,ymax);
line(x1,y1,x2,y2);
getch();
}
else
{
cleardevice();
printf("\n\t\tLine is partially visible");
rectangle(xmin,ymin,xmax,ymax);
line(x1,y1,x2,y2);
getch();
if((start[2]==0)&&(start[3]==1))
{
x1=x1+(ymin-y1)/m;
y1=ymin;
}
if((end[2]==0)&&(end[3]==1))
{
x2=x2+(ymin-y2)/m;
y2=ymin;
}
if((start[2]==1)&&(start[3]==0))
{
x1=x1+(ymax-y1)/m;
y1=ymax;
}
if((end[2]==1)&&(end[3]==0))
{
x2=x2+(ymax-y2)/m;
y2=ymax;
}
if((start[1]==0)&&(start[0]==1))
{
y1=y1+m*(xmin-x1);
x1=xmin;
}
if((end[1]==0)&&(end[0]==1))
{
y2=y2+m*(xmin-x2);
x2=xmin;
}
if((start[1]==1)&&(start[0]==0))
{
y1=y1+m*(xmax-x1);
x1=xmax;
}
if((end[1]==1)&&(end[0]==0))
{
y2=y2+m*(xmax-x2);
x2=xmax;
}
clrscr();
cleardevice();
printf("\n\t\tAfter clippling:");
rectangle(xmin,ymin,xmax,ymax);
line(x1,y1,x2,y2);
getch();
}
}
else
{
clrscr();
cleardevice();
printf("\nLine is invisible");
rectangle(xmin,ymin,xmax,ymax);
}
getch();
closegraph();
}
OUTPUT
6.2D TRANSFORMATION
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<math.h>
void main()
{
int gm;
int gd=DETECT;
int x1,x2,x3,y1,y2,y3,nx1,nx2,nx3,ny1,ny2,ny3,c;
int sx,sy,xt,yt,r;
float t;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
printf("\t Program for basic transactions");
printf("\n\t Enter the points of triangle");
setcolor(1);
scanf("%d %d %d %d %d %d", &x1, &y1, &x2, &y2, &x3, &y3);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
getch();
do
{
printf("\n 1.Translatin\n 2.Rotation\n 3.Scalling\n 4.exit");
printf("\nEnter your choice:");
scanf("%d",&c);
switch(c)
{
case 1:
printf("\n Enter the translation factor");
scanf("%d%d",&xt,&yt);
nx1=x1+xt;
ny1=y1+yt;
nx2=x2+xt;
ny2=y2+yt;
nx3=x3+xt;
ny3=y3+yt;
line(nx1,ny1,nx2,ny2);
line(nx2,ny2,nx3,ny3);
line(nx3,ny3,nx1,ny1);
getch();
break;
case 2:
printf("\n Enter the angle of rotation");
scanf("%d",&r);
t=3.14*r/180;
nx1=abs(x1*cos(t)-y1*sin(t));
ny1=abs(x1*sin(t)+y1*cos(t));
nx2=abs(x2*cos(t)-y2*sin(t));
ny2=abs(x2*sin(t)+y2*cos(t));
nx3=abs(x3*cos(t)-y3*sin(t));
ny3=abs(x3*sin(t)+y3*cos(t));
line(nx1,ny1,nx2,ny2);
line(nx2,ny2,nx3,ny3);
line(nx3,ny3,nx1,ny1);
getch();
break;
case 3:
printf("\n Enter the scalling factor");
scanf("%d%d",&sx,&sy);
nx1=x1*sx;
ny1=y1*sy;
nx2=x2*sx;
ny2=y2*sy;
nx3=x3*sx;
ny3=y3*sy;
line(nx1,ny1,nx2,ny2);
line(nx2,ny2,nx3,ny3);
line(nx3,ny3,nx1,ny1);
getch();
break;
case 4:
exit(0);
default:
printf("Enter the correct choice");
}
}
while(1);
closegraph();
}
OUTPUT
7. GREETING CARD DESIGN
8. LETTER PAD AND VISITING CARD DESIGN
9.BUTTERFLY ANIMATION
10.TEXT ANIMATION