Sie sind auf Seite 1von 17

AIM(1): WAP to print a pixel.

Program:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
Void main()
{
Int gd=DETECT,gm;
Initgraph(&gd.&gm,C:\\TC\\BGI);
Cleardevice();
Putpixel(500,320,2);
Getch();
}

AIM(1): WAP to print a pixel.


Output:

AIM(2): WAP to print circle, line, arc, ellipse.


Program:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
Void main()
{
Int gd=DETECT,gm;
Initgraph(&gd, &gm,C:\\TC\\BGI);
Cleardevice();
Setcolor(3);
Circle(320,220,177);
Setcolor(2);
Ellipse(220,180,0,360,30,20);
Setcolor(4);
Ellipse(420,180,0,360,30,20);
Setcolor(5);
Line(320,120,320,250);
Setcolor(6);
Arc(320,270,180,0,50);
Getch();
}

AIM(2): WAP to print circle, line, arc, ellipse.


Output:

AIM(3): WAP to draw a line using DDA algorithm.


Program:
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
int x1,x2,y1,y2,dx,dy,steps,k;
float xi,yi,x,y;
clrscr();
initgraph (&gd,&gm,"C:\\TC\\BGI");
cout<<"Enter the co-ordinates of the first point \n";
cout<<"x1= ";
cin>>x1;
Cout<<"y1= ";
Cin>>y1;
cout<<"Enter the co-ordinates of the second point \n";
cout<<"x2= ";
cin>>x2;
cout<<"y2= ";
cin>>y2;
clrscr();
dx= x2-x1;
dy= y2-y1;
if (abs(dx) > abs(dy))
steps = abs(dx);
else
steps = abs(dy);
xi=dx/steps;
yi=dy/steps;
x=x1;
y=y1;
for(k=0;k<steps;k++)
{
putpixel (x,y,BLUE);
x=x+xi;
y=y+yi;
}
getch();

closegraph();
}

AIM(3): WAP to draw a line using DDA algorithm.


Output:
Enter the co-ordinates of the first point
x1=300
y1=120
Enter the co-ordinates of the second point
x2=300
y2=250

AIM(4): WAP to draw a circle using Bresenhams algorithm.


Program:
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
Void circlepoints(int,int);
Void main();
{
Int gd=DETECT,gm;
Initgraph(&gd, &gm, c:\\tc\\bgi);
Clrscr();
Cout<<enter the radius:
Cin>>r;
X=0;
Y=r;
P=1-r;
While(x<y)
{
X++;
If(p>0);
{
P=p+2*(x-y)+1;
y--;
}
Else
{
P=p+2*x+1;
}
Circlepoints(x, y);
}Getch();
Closegraph();
}
Void circlepoints(int x, int y)
{
Putpixel(x+300,y+300,8);
Putpixel(x+300,-y+300,8);
Putpixel(-x+300,y+300,8);
Putpixel(-x+300,-y+300,8);
Putpixel(y+300,x+300,8);
Putpixel(y+300,-x+300,8);
Putpixel(-y+300,x+300,8);
Putpixel(-y+300,-x+300,8);
}

AIM(4): WAP to draw a circle using Bresenhams algorithm.


Output:

Enter the radius 90

AIM(5): WAP to fill polygon by using boundary fill algorithm.


Output:
# include <iostream.h>
# include <graphics.h>
# include <conio.h>
# include <math.h>
void Boundary_fill(int,int,int,int);
void Circle(int,int,int);
int main( )
{
Int gd=DETECT,gm;
Initgraph(&gd, &gm, c:\\tc\\bgi);
setcolor(15);
Circle(175,175,40);
Boundary_fill(175,175,10,15);
getch( );
return 0;
}
void Boundary_fill(int x,int y,int fill_color,int
boundary_color)
{
if(getpixel(x,y)!=boundary_color &&
getpixel(x,y)!=fill_color)
{
putpixel(x,y,fill_color);
Boundary_fill((x+1),y,fill_color,boundary_color);
Boundary_fill((x-1),y,fill_color,boundary_color);
Boundary_fill(x,(y+1),fill_color,boundary_color);
Boundary_fill(x,(y-1),fill_color,boundary_color);
}
}
void Circle(const int h,const int k,const int r)
{
int color=getcolor( );
int x=0;
int y=r;
int p=(1-r);
do
{

putpixel((h+x),(k+y),color);
putpixel((h+y),(k+x),color);
putpixel((h+y),(k-x),color);
putpixel((h+x),(k-y),color);
putpixel((h-x),(k-y),color);
putpixel((h-y),(k-x),color);
putpixel((h-y),(k+x),color);
putpixel((h-x),(k+y),color);
x++;
if(p<0)
p+=((2*x)+1);
else
{
y--;
p+=((2*(x-y))+1);
}
}
while(x<=y);
}

AIM(5): WAP to fill polygon by using boundary fill algorithm.


Output:

AIM(6): WAP to fill rectangle by using flood fill algorithm.


Program:
# include <iostream.h>
# include <graphics.h>
# include <conio.h>
# include <math.h>
void Flood_fill(const int,const int,const int,const int);
void Rectangle(const int,const int,const int,const int);
int main( )
{
Int gd=DETECT,gm;
Initgraph(&gd, &gm, c:\\tc\\bgi);
setcolor(15);
Rectangle(375,145,475,205);
Flood_fill(400,175,9,0);
getch( );
return 0;
}
void Flood_fill(const int x,const int y,const int
fill_color,const int old_color)
{
if(getpixel(x,y)==old_color)
{
putpixel(x,y,fill_color);
Flood_fill((x+1),y,fill_color,old_color);
Flood_fill((x-1),y,fill_color,old_color);
Flood_fill(x,(y+1),fill_color,old_color);
Flood_fill(x,(y-1),fill_color,old_color);
}
}
void Rectangle(const int x_1,const int y_1,const int
x_2,const int y_2)
{
Line(x_1,y_1,x_2,y_1);
Line(x_2,y_1,x_2,y_2);
Line(x_2,y_2,x_1,y_2);
Line(x_1,y_2,x_1,y_1);
}

AIM(6): WAP to fill rectangle by using flood fill algorithm.


Output:

AIM(7): WAP to rotate a triangle about origin.


Program:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<process.h>
#include<math.h>
Void main()
{
Clrscr();
Int gd=DETECT,gm;
Initgraph(&gd, &gm, C:\\TC\\BGI);
Int x, y, l, a[3][3];
Double b[3][3], c[3][3];
Cout<<\n enter 1st coordinates of triangle;
Cin>>a[0][0]>>a[1][1];
Cout<<\n enter 2nd coordinates of ttraingle;
Cin>>a[0][1]>>a[1][1];
Cout<<\n enter 3rd coordinates of triangle;
Cin>>a[0][2]>>a[1][2];
Line(a[0][0],a[1][0],a[0][1].a[1][1]);
Line(a[0][1],a[1][1],a[0][2],a[1][2]);
Line(a[0][0],a[1][0],a[0][2],a[1][2]);
Getch();
Cleardevice();
Cout<<\n enter angle of raotation;\n;
Cin>>x;
B[0][0]=b[1][1]=cos((x*3.14)/180);
B[0][1]=sin((x*3.14)/180);
B[1][0]=sin((x*3.14)/180);
B[2][2]=1;
B[2][0]=b[2][1]=b[0][2]=b[1][2]=0;
For(int i=0;i<3;i++)
{
For(int j=0;j<3;j++)
{
For(int k=0;k<3;k++)
{
C[i][j]+=a[i][k]*b[k][j];
}
X1=(c[i][j]+0.5);

A[i][j]=x1;
}
}
Cout<<\n tringe after rotation is :\n;
Line(a[0][0],a[1][0],a[0][1],a[1][1]);
Line(a[0][1],a[1][1],a[0][2],a[1][2]);
Line(a[0][0],a[1][0],a[0][2],a[1][2]);
Getch();
Closegraph();
}

AIM(7): WAP to rotate a triangle about origin.


Output:
Enter 1st coordinates of triangle:100
100
Enter 2nd coordinates of triangle:200
100
Enter 3rd coordinates of triangle:150
50

Enter angle of rotation :30


Tringle after rotation is:

Das könnte Ihnen auch gefallen