Draw a line accroding to breshenham algorithm

void bresline(Point start,Point end,Color thisColor){

 int x,y,endl,steps=0,p,dx,dy ,c=0,current=0;

    dx=abs(end.x -start.x ); //abs of delta x
	dy=abs(end.y -start.y ); //abs of delta y

	if(dx>dy)
 			{
 				p=2*dy-dx;
  				if(start.x<end.x)
  				  {
   					 x=start.x;
					 y=start.y;
					 endl=end.x;

					 if(start.y x at start
  				{
   					x=end.x;
					y=end.y;
					endl=start.x;

   					if(end.y<start.y)
						steps=1;
					else
						steps=-1;
  				}
  				while(x<=endl)
  				{
  					setPixel(x,y,thisColor);

  					if(pdx
			{
				p=2*dx-dy;
				if(start.y<end.y)
				{
					y=start.y;
					x=start.x;
					endl=end.y;

					if(start.x<end.x)
						steps=1;
					else
						steps=-1;
				}
				else
				{
					y=end.y;
					x=end.x;
					endl=start.y;

					if(end.x<start.x)
						steps=1;
					else
						steps=-1;
				}
				while(y<=endl)
  				{
 					setPixel(x,y,thisColor);

 					if(p<0)
						p=p+2*dx;
 					else
 						{
 							x=x+steps;
							p=p+2*(dx-dy);
   						}
   					y++;

   					if(current==0&&c==10)
   					{
    						current=1;
							c=-1;
   					}

   					if(current==1&&c==6)
   					{
   						current=0;
						c=-1;
   					}
   					c++;
  				}//while
 	}//1st if

}//bresline

One Response to “Draw a line accroding to breshenham algorithm”

  1. how women pee Says:

    hm.. nice..

Leave a Reply