Friday 26 September 2014

Hashing in MySQL

Password Hashing in MySQL

MySQL lists user accounts in the user table of the mysql database. Each MySQL account can be assigned a password, although the user table does not store the cleartext version of the password, but a hash value computed from it.

MySQL uses passwords in two phases of client/server communication:

When a client attempts to connect to the server, there is an initial authentication step in which the client must present a password that has a hash value matching the hash value stored in the user table for the account the client wants to use.

After the client connects, it can (if it has sufficient privileges) set or change the password hash for accounts listed in the user table. The client can do this by using the PASSWORD() function to generate a password hash, or by using a password-generating statement (CREATE USER, GRANT, or SET PASSWORD).

In other words, the server checks hash values during authentication when a client first attempts to connect. The server generates hash values if a connected client invokes the PASSWORD() function or uses a password-generating statement to set or change a password.

Password hashing methods in MySQL have the history described following. These changes are illustrated by changes in the result from the PASSWORD() function that computes password hash values and in the structure of theuser table where passwords are stored.

Example 

Trigger

Introduction to SQL Trigger


Summary: in this tutorial, we will  give you a brief overview of SQL trigger, its advantages and disadvantages.

A SQL trigger is a set of  SQL statements stored in the database catalog. A SQL trigger is executed or fired whenever an event associated with a table occurs e.g.,  insert, update or delete.

A SQL trigger is a special type of stored procedure. It is special because it is not called directly like a stored procedure. The main difference between a trigger and a stored procedure is that a trigger is called automatically when a data modification event is made against a table whereas a stored procedure must be called explicitly.

It is important to understand SQL trigger’s advantages and disadvantages so that you can use it appropriately. In the following sections, we will discuss about the advantages and disadvantages of using SQL triggers.

Advantages of using SQL triggers

SQL triggers provide an alternative way to check the integrity of data.
SQL triggers can catch errors in business logic in the database layer.
SQL triggers provide an alternative way to run scheduled tasks. By using SQL triggers, you don’t have to wait to run the scheduled tasks because the triggers are invoked  automatically before or after a change  is made to the data in tables.
SQL triggers are very useful to audit the changes of data in tables.
Disadvantages of using SQL triggers

SQL triggers only can provide an extended validation and they cannot replace all the validations. Some simple validations have to be done in the application layer. For example, you can validate user’s inputs in the client side by using JavaScript or in the server side using server side scripting languages such as JSP, PHP, ASP.NET, Perl, etc.
SQL triggers are invoked and executed invisibly from client-applications therefore it is difficult to figure out what happen in the database layer.
SQL triggers may increase the overhead of the database server.

CREATE TRIGGER Syntax


CREATE
    [DEFINER = { user | CURRENT_USER }]
    TRIGGER trigger_name trigger_time trigger_event
    ON tbl_name FOR EACH ROW trigger_stmt

DROP TRIGGER Syntax

DROP TRIGGER [IF EXISTS] [schema_name.]trigger_name

Example 

Thursday 25 September 2014

Program to generate 3D Object using Polygon Surfaces and then perform 3D transformation.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>         
void trans();
//void axis();
void scale();
void rotate();
int maxx,maxy,midx,midy;
/*void axis()
{
//          getch();
  //        cleardevice();
            line(midx,0,midx,maxy);
            line(0,midy,maxx,midy);
}*/
void main()
{
            int ch;
            int gd=DETECT,gm;
            detectgraph(&gd,&gm);
            initgraph(&gd,&gm,"e:\\tc\\bgi");
            printf("\n 1.Translation \n2.Scaling\n 3.Rotation \n 4.exit");
            printf("enter your choice");
            scanf("%d",&ch);
            do
            {
                        switch(ch)
                        {
                                    case 1 :             trans();
                                                            getch();
                                                      //    closegraph();
                                                            break;

                                    case 2 :             scale();
                                                            getch();
                                                      //    closegraph();
                                                            break;

                                    case 3 :             rotate();
                                                            getch();
                                                    //      closegraph();
                                                            break;

                                    case 4 :        break;
                        }
                        printf("enter your choice");
                        scanf("%d",&ch);
            } while(ch<4);
}
void trans()
{
            int x,y,z,o,x1,x2,y1,y2;
            maxx=getmaxx();
            maxy=getmaxy();
            midx=maxx/2;
            midy=maxy/2;
            //axis();
            bar3d(midx+50,midy-100,midx+60,midy-90,10,1);
            printf("Enter translation factor");
            scanf("%d%d",&x,&y);
            printf("After translation:");
            bar3d(midx+x+50,midy-(y+100),midx+x+60,midy-(y+90),10,1);
}
void scale()
{
            int x,y,z,o,x1,x2,y1,y2;
            maxx=getmaxx();
            maxy=getmaxy();
            midx=maxx/2;
            midy=maxy/2;
            //axis();
            bar3d(midx+50,midy-100,midx+60,midy-90,5,1);
            printf("before translation\n");
            printf("Enter scaling factors\n");
            scanf("%d %d %d", &x,&y,&z);
            printf("After scaling\n");
            bar3d(midx+(x*50),midy-(y*100),midx+(x*60),midy-(y*90),5*z,1);
}
void rotate()
{
            int x,y,z,o,x1,x2,y1,y2;
            maxx=getmaxx();
            maxy=getmaxy();
            midx=maxx/2;
            midy=maxy/2;
            //axis();
            bar3d(midx+50,midy-100,midx+60,midy-90,5,1);
            printf("Enter rotating angle");
            scanf("%d",&o);
            x1=50*cos(o*3.14/180)-100*sin(o*3.14/180);
            y1=50*sin(o*3.14/180)+100*cos(o*3.14/180);
            x2=60*cos(o*3.14/180)-90*sin(o*3.14/180);
            y2=60*sin(o*3.14/180)+90*cos(o*3.14/180);
   //       axis();
    //      printf("After rotation about z axis");
    //      bar3d(midx+x1,midy-y1,midx+x2,midy-y2,5,1);
            //axis();
            printf("After rotation  about x axis");
            bar3d(midx+50,midy-x1,midx+60,midy-x2,5,1);
            //axis();
            printf("After rotation about yaxis");
            bar3d(midx+x1,midy-100,midx+x2,midy-90,5,1);

}

Program for implementation of Cohen –Sutherland Line clipping algorithm.

#include <conio.h>
#include <iostream.h>
#include <graphics.h>
typedefstruct coordinate
                {
                intx,y;
                char code[4];
                }PT;
voiddrawwindow();
voiddrawline (PT p1,PT p2,int cl);
PT setcode(PT p);
int visibility (PT p1,PT p2);
PT resetendpt (PT p1,PT p2);
main()
                {
                intgd=DETECT, gm,v;
                PT p1,p2,ptemp;
                initgraph(&gd,&gm,"C:\\TurboC3\\bgi");
                cleardevice();
                cout<<"\n\n\t\tENTER END-POINT 1 (x,y): ";
                cin>>p1.x>>p1.y;
                cout<<"\n\n\t\tENTER END-POINT 2 (x,y): ";
                cin>>p2.x>>p2.y;
                cleardevice();
                drawwindow();
                getch();
                drawline(p1,p2,15);
                getch();
                p1=setcode(p1);
                p2=setcode(p2);
                v=visibility(p1,p2);
                switch(v)
                                {
                                case 0:
                                                cleardevice();    /* Line conpletely visible */
                                                drawwindow();
                                                drawline(p1,p2,15);
                                                break;
                                case 1:
                                                cleardevice();    /* Line completely invisible */
                                                drawwindow();
                                                break;
                                case 2: cleardevice();      /* line partly visible */
                                                p1=resetendpt (p1,p2);
                                                p2=resetendpt(p2,p1);
                                                drawwindow();
                                                drawline(p1,p2,15);
                                                break;
                                }
                getch();
                closegraph();
                return(0);
                }
voiddrawwindow()
                {
                setcolor(RED);
                line(150,100,450,100);
                line(450,100,450,350);
                line(450,350,150,350);
                line(150,350,150,100);
                }
voiddrawline (PT p1,PT p2,int cl)
                {
                setcolor(cl);
                line(p1.x,p1.y,p2.x,p2.y);
                }
PT setcode(PT p)
                {
                PT ptemp;
                if(p.y<100)
                                ptemp.code[0]='1';
                else
                                ptemp.code[0]='0';
                if(p.y>350)
                                ptemp.code[1]='1';
                else
                                ptemp.code[1]='0';
                if (p.x>450)
                                ptemp.code[2]='1';
                else
                                ptemp.code[2]='0';
                if (p.x<150) /* LEFT */
                                ptemp.code[3]='1';
                else
                                ptemp.code[3]='0';
                ptemp.x=p.x;
                ptemp.y=p.y;
                return(ptemp);
                }
int visibility (PT p1,PT p2)
                {
                inti,flag=0;
                for(i=0;i<4;i++)
                                {
                                if((p1.code[i]!='0')||(p2.code[i]!='0'))
                                flag=1;
                                }
                if(flag==0)
                                return(0);
                for(i=0;i<4;i++)
                                {
                                if((p1.code[i]==p2.code[i]) &&(p1.code[i]=='1'))
                                flag=0;
                                }
                if(flag==0)
                                return(1);
                return(2);
                }
PT resetendpt (PT p1,PT p2)
                {
                PT temp;
                intx,y,i;
                floatm,k;
                if( p1.code[3]=='1')
                                x=150;
                if(p1.code[2]=='1')
                                x=450;
                if((p1.code[3]=='1')||(p1.code[2]=='1'))
                                {
                                m=(float) (p2.y-p1.y)/(p2.x-p1.x);
                                k=(p1.y+(m*(x-p1.x)));
                                temp.y=k;
                                temp.x=x;
                                for(i=0;i<4;i++)
                                                temp.code[i]=p1.code[i];
                                if(temp.y<=350&&temp.y>=100)
                                                return(temp);
                                }
                if(p1.code[0]=='1')
                                y=100;
                if(p1.code [1]=='1')
                                y=350;
                if((p1.code[0]=='1')||(p1.code[1]=='1'))
                                {
                                m=(float)(p2.y-p1.y)/(p2.x-p1.x);
                                k=(float)p1.x+(float)(y-p1.y)/m;
                                temp.x=k;
                                temp.y=y;
                                for(i=0;i<4;i++)
                                                temp.code[i]=p1.code[i];
                                return(temp);
                                }
                else
                                return(p1);

                }

Programs using 2­D transformations­ Translations, rotation, scaling.reflection, shear using homogeneous matrix representation.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
#include<stdlib.h>
void menu();
void input();
void output();
void translation();
void rotation();
void scaling();
void shearing();
void reflection();
int gd,gm;
int a[10][2],i,x,option,temp,angle,tx,ty,fx,fy,sh,k,n,axis,y;
float sx,sy;
void menu()
{
printf("menu\n");
printf("1.Translation\n");
printf("2.rotation\n");
printf("3.scaling\n");
printf("4.shearing\n");
printf("5.reflection\n");
printf("6.exit\n");
printf("enter the choice:");
scanf("%d",&option);
switch(option)
                                                {
case  1:
input();
translation();
break;
case 2:
input();
rotation();
break;
case 3:
input();
scaling();
break;
case 4 :
input();
shearing();
break;
case 5:
input();
reflection();
break;
case 6:
exit(0);
break;
                                       }
}
void input()
{
printf("enter the number of vertices:" );
scanf("%d",&n);
for(i=0;i<n;i++)
                                                {
printf("enter the coordinates:");
scanf("%d%d%d%d",&a[i][0],&a[i][1],&a[i+1][0],&a[i+1][1]);
                                       }
}
void output()
{
cleardevice();
for(i=0;i<n;i++)
                                       {
                                                                   line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]);
                                                }
}
void translation()
{
output();
printf("enter the tranformation vertex tx,ty:\n");
scanf("%d%d",&tx,&ty);
for(i=0;i<=n;i++)
                                                {
a[i][0]=a[i][0]+tx;
a[i][1]=a[i][1]+ty;
                                                }
output();
delay(10);
menu();
}
void rotation()
{
output();
printf("enter the rotating angle:");
scanf("%d",&y);
printf("enter the pivot point:");
scanf("%d%d",&fx,&fy);
                                                k=(y*3.14)/180;
for(i=0;i<=n;i++)
                                                {
                                                                    a[i][0]=fx+(a[i][0]-fx)*cos(k)-(a[i][1]-fy)*sin(k);
                                                                    a[i][1]=fy+(a[i][0]-fx)*sin(k)-(a[i][1]-fy)*cos(k);
                                                }
output();
delay(10);
menu();
}
void scaling()
{
output();
printf("enter the scaling factor\n");
scanf("%f%f",&sx,&sy);
printf("enter the fixed point:");
scanf("%d%d",&fx,&fy);
for(i=0;i<=n;i++)
                                                {
a[i][0]=a[i][0]*sx+fy*(1-sx);
a[i][1]=a[i][1]*sy+fy*(1-sy);
                                                }
output();
delay(10);
menu();
}
void shearing()
{
output();
printf("enter the shear value:");
scanf("%d",&sh);
printf("enter the fixed point:");
scanf("%d%d",&fx,&fy);
printf("enter the axis for shearing if x-axis then 1 if y-axis the 0:");
scanf("%d",&axis);
for(i=0;i<=n;i++)
                                                {
if(axis==1)
                                                                    {
a[i][0]=a[i][0]+sh*(a[i][1]-fy);
                                                                    }
else
                                                                    {
a[i][1]=a[i][1]+sh*(a[i][0]-fx);
                                                                    }
                                                }
output();
delay(10);
menu();
}
void reflection()
{
output();
for(i=0;i<=n;i++)
                                                {
temp=a[i][0];
a[i][0]=a[i][1];
a[i][1]=temp;
                                                }
output();
delay(10);
menu();
}
void main()
{
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\bgi");
menu();           getch();   

}



Program to implement curve generation using Bezeir curve algorithm.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int x,y,z;
void main()
{
float u;
int gd,gm,ymax,i,n,c[4][3];
for(i=0;i<4;i++)
{
c[i][0]=0;
c[i][1]=0;
}
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"e:\\tc\\bgi");
printf("\n\n Enter four points : \n\n");
for(i=0; i<4; i++)
{
printf("\t X%d Y%d : ",i,i);
scanf("%d %d",&c[i][0],&c[i][1]);
}
c[4][0]=c[0][0];
c[4][1]=c[0][1];
ymax = 480;
setcolor(13);
for(i=0;i<3;i++)
{
line(c[i][0],ymax-c[i][1],c[i+1][0],ymax-c[i+1][1]);
}
setcolor(3);
n=3;
for(i=0;i<=40;i++)
{
u=(float)i/40.0;
bezier(u,n,c);
if(i==0)
moveto(x,ymax-y);
else
{
lineto(x,ymax-y); }
getch();
}
getch();
}
bezier(u,n,p)
float u;int n; int p[4][3];
{
int j;
float v,b;
float blend(int,int,float);
x=0;y=0;z=0;
for(j=0;j<=n;j++)
{
b=blend(j,n,u);
x=x+(p[j][0]*b);
y=y+(p[j][1]*b);
z=z+(p[j][2]*b);
}
}
float blend(int j,int n,float u)
{
int k;
float v,blend;
v=C(n,j);
for(k=0;k<j;k++)
{ v*=u; }
for(k=1;k<=(n-j);k++)
{ v *= (1-u); }
blend=v;
return(blend);
}C(int n,int j)
{
int k,a,c;
a=1;
for(k=j+1;k<=n;k++) { a*=k; }
for(k=1;k<=(n-j);k++) { a=a/k; }
c=a;
return(c);
}







OUTPUT


Program for implementation of Flood fill & Boundary Fill polygon filling method.

# include <iostream.h>
 # include <graphics.h>
 # include    <conio.h>
 # include     <math.h>
 void Flood_fill(const int,const int,const int,const int);
 void Circle(const int,const int,const int);
 void Triangle(const int,const int,const int,const int,const int,const int);
 void Rectangle(const int,const int,const int,const int);
 void Polygon(const int,const int []);
 void Line(const int,const int,const int,const int);
 int main( )
    {
       int driver=VGA;
       int mode=VGAHI;
       initgraph(&driver,&mode,"..\\Bgi");
         setcolor(15);
                 Circle(175,175,40);
                 Flood_fill(175,175,10,0);
       setcolor(15);
       settextstyle(0,0,1);
                 outtextxy(150,225,"Circle");
       setcolor(15);
                 Rectangle(375,145,475,205);
                 Flood_fill(400,175,9,0);
       setcolor(15);
       settextstyle(0,0,1);
                 outtextxy(390,215,"Rectangle");
       setcolor(15);
                 Triangle(135,360,215,360,175,290);
                 Flood_fill(175,325,8,0);
       setcolor(15);
       settextstyle(0,0,1);
                 outtextxy(145,370,"Triangle");
       int polygon_points[14]={ 365,325, 400,290, 450,290, 485,325,450,360, 400,360, 365,325 };
      setcolor(15);
                 Polygon(7,polygon_points);

                 Flood_fill(425,325,12,0);
       setcolor(15);
       settextstyle(0,0,1);
                 outtextxy(395,370,"Polygon");
       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 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);
    }
 void Triangle(const int x_1,const int y_1,const int x_2,const int y_2,const int x_3,const int y_3)
    {
       Line(x_1,y_1,x_2,y_2);
       Line(x_2,y_2,x_3,y_3);
       Line(x_3,y_3,x_1,y_1);
    }
 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);
    }
 void Polygon(const int n,const int coordinates[])
    {
       if(n>=2)
                  {
                     Line(coordinates[0],coordinates[1],coordinates[2],coordinates[3]);
                     for(int count=1;count<(n-1);count++)
Line(coordinates[(count*2)],coordinates[((count*2)+1)],coordinates[((count+1)*2)], coordinates[(((count+1)*2)+1)]);
                  }
    }
 void Line(const int x_1,const int y_1,const int x_2,const int y_2)
    {
       int color=getcolor( );
       int x1=x_1;
       int y1=y_1;
       int x2=x_2;
       int y2=y_2;
       if(x_1>x_2)
                  {
                     x1=x_2;
                     y1=y_2;
                     x2=x_1;
                     y2=y_1;
                  }
       int dx=abs(x2-x1);
       int dy=abs(y2-y1);
       int inc_dec=((y2>=y1)?1:-1);
       if(dx>dy)
                  {
                     int two_dy=(2*dy);
                     int two_dy_dx=(2*(dy-dx));
                     int p=((2*dy)-dx);
                     int x=x1;
                     int y=y1;
                     putpixel(x,y,color);
                     while(x<x2)
                                {
                                   x++;
                                   if(p<0)
                                      p+=two_dy;
                                   else
                                      {
                                                 y+=inc_dec;
                                                 p+=two_dy_dx;
                                      }
                                   putpixel(x,y,color);
                                }
                  }
       else
                  {
                     int two_dx=(2*dx);
                     int two_dx_dy=(2*(dx-dy));
                     int p=((2*dx)-dy);
                     int x=x1;
                     int y=y1;
                     putpixel(x,y,color);
                     while(y!=y2)
                                {
                                   y+=inc_dec;
                                   if(p<0)
                                      p+=two_dx;
                                   else
                                      {
                                                 x++;
                                                 p+=two_dx_dy;
                                      }
                                   putpixel(x,y,color);
                                }
                  }
    }






OUTPUT




# include <iostream.h>
# include <graphics.h>
# include <conio.h>
# include <math.h>
void show_screen( );
void Boundary_fill(const int,const int,const int,const int);
void Circle(const int,const int,const int);
void Triangle(const int,const int,const int,const int,const int,const int);
void Rectangle(const int,const int,const int,const int);
void Polygon(const int,const int []);
void Line(const int,const int,const int,const int);
int main( )
 {
 int driver=VGA;
 int mode=VGAHI;
 initgraph(&driver,&mode,"..\\Bgi");
 show_screen( );
 setcolor(15);
Circle(175,175,40);
Boundary_fill(175,175,10,15);
 setcolor(15);
 settextstyle(0,0,1);
outtextxy(150,225,"Circle");
 setcolor(15);
Rectangle(375,145,475,205);
Boundary_fill(400,175,9,15);
 setcolor(15);
 settextstyle(0,0,1);
outtextxy(390,215,"Rectangle");
setcolor(15);
Triangle(135,360,215,360,175,290);
Boundary_fill(175,325,8,15);
 setcolor(15);
 settextstyle(0,0,1);
outtextxy(145,370,"Triangle");
 int polygon_points[14]={ 365,325, 400,290, 450,290, 485,32,
450,360, 400,360, 365,325 }; setcolor(15);
Polygon(7,polygon_points);
Boundary_fill(425,325,12,15);
 setcolor(15);
 settextstyle(0,0,1);
outtextxy(395,370,"Polygon");
 getch( );
 return 0;
 }
void Boundary_fill(const int x,const int y,
const int fill_color,const 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);
 }
void Triangle(const int x_1,const int y_1,const int x_2,const int y_2,const int x_3,const int y_3)
 {
 Line(x_1,y_1,x_2,y_2);
 Line(x_2,y_2,x_3,y_3);
 Line(x_3,y_3,x_1,y_1);
 }
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);
 }
void Polygon(const int n,const int coordinates[])
 {
 if(n>=2)
 {
 Line(coordinates[0],coordinates[1],
 coordinates[2],coordinates[3]);
 for(int count=1;count<(n-1);count++)
Line(coordinates[(count*2)],coordinates[((count*2)+1)],
coordinates[((count+1)*2)],
 coordinates[(((count+1)*2)+1)]);
 }
 }
void Line(const int x_1,const int y_1,const int x_2,const int y_2)
 {
 int color=getcolor( );
 int x1=x_1; int y1=y_1;
 int x2=x_2;
 int y2=y_2;
 if(x_1>x_2)
 {
 x1=x_2;
 y1=y_2;
 x2=x_1;
 y2=y_1;
 }
 int dx=abs(x2-x1);
 int dy=abs(y2-y1);
 int inc_dec=((y2>=y1)?1:-1);
 if(dx>dy)
 {
 int two_dy=(2*dy);
 int two_dy_dx=(2*(dy-dx));
 int p=((2*dy)-dx);
 int x=x1;
 int y=y1;
 putpixel(x,y,color);
 while(x<x2)
{
 x++;
 if(p<0)
 p+=two_dy;
 else
 {
y+=inc_dec;
p+=two_dy_dx;
 }
 putpixel(x,y,color);
}
 }
 else
 {
 int two_dx=(2*dx);
 int two_dx_dy=(2*(dx-dy));
 int p=((2*dx)-dy);
 int x=x1; int y=y1;
 putpixel(x,y,color);
 while(y!=y2)
{
 y+=inc_dec;
 if(p<0)
 p+=two_dx;
 else
 {
x++;
p+=two_dx_dy;
 }
 putpixel(x,y,color);
}
 }
 }
void show_screen( )
 {
 setfillstyle(1,1);
bar(220,26,420,38);
 settextstyle(0,0,1);
setcolor(15);
outtextxy(5,5,"*****************************************************************
*************");
outtextxy(5,17,"****************************************************************
***********-*");
outtextxy(5,29,"*-------------------------------------------------*");
outtextxy(5,53,"****************************************************************
***********-*");
setcolor(11);
 outtextxy(228,29,"Boundary Fill Algorithm");
setcolor(15);
 for(int count=0;count<=30;count++)
 outtextxy(5,(65+(count*12)),"*-* *-*");
outtextxy(5,438,"***************************************************************
************-*");outtextxy(5,450,"*--------------------------------------------------*");
outtextxy(5,462,"***************************************************************
***************");
setcolor(12);
 outtextxy(229,450,"Press any Key to exit.");
 }










OUTPUT