Hi!
I`m trying to draw a rectangle in c++ but it doesnt run!
it compiles successfully! but when i run it ,it doesnt show anything on the screen
plz guys! what should i do?
this is my code:
Code:
void box(int startx, int starty, int endx, int endy, int color)
{
line(startx , starty , endx , starty , color) ;
line(startx , starty , startx , endy , color) ;
line(startx , endy , endx , endy , color) ;
line(endx , starty , endx , endy , color) ;
}
void line(int startx, int starty, int endx, int endy, int color)
{
register int t , distance ;
int xerr = 0 , yerr = 0 , deltax , deltay ;
int incx , incy ;
deltax = endx - startx ;
deltay = endy - starty ;
if(deltax > 0)
incx = 1 ;
else if(deltax == 0)
incx = 0 ;
else
incx =- 1 ;
if(deltay > 0)
incy = 1 ;
else if(deltay == 0)
incy = 0 ;
else
incy =- 1 ;
deltax = abs(deltax) ;
deltay = abs(deltay) ;
if(deltax > deltay)
distance = deltax ;
else
distance = deltay ;
for(t = 0 ; t < distance + 1 ; t++) {
mempoint(startx , starty , color) ;
xerr += deltax ;
yerr += deltay ;
if(xerr > distance) {
xerr -= distance ;
startx+=incx ;
}
if(yerr > distance) {
yerr -= distance ;
starty+=incy ;
}
}
}