You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// use Bresenham-like algorithm to print a line from (y1,x1) to (y2,x2)// The difference with Bresenham is that ALL the points of the line are// printed, not only one per x coordinate.// Principles of the Bresenham's algorithm (heavily modified) were taken from:// http://www.intranet.ca/~sshah/waste/art7.htmlvoiduseVisionLine (inty1, intx1, inty2, intx2)
{
inti; // loop counterintystep, xstep; // the step on y and x axisinterror; // the error accumulated during the incrementinterrorprev; // *vision the previous value of the error variableinty=y1, x=x1; // the line pointsintddy, ddx; // compulsory variables: the double values of dy and dxintdx=x2-x1; //(dx/=tile.w)intdy=y2-y1; //(dy/=tile.h)POINT (x1, y1); // first point// NB the last point can't be here, because of its previous point (which has to be verified)if (dy<0) {
ystep=-1;
dy=-dy;
} else {
ystep=1;
}
if (dx<0) {
xstep=-1;
dx=-dx;
} else {
xstep=1;
}
ddy=2*dy; // work with double values for full precisionddx=2*dx;
if (ddx >= ddy){ // first octant (0 <= slope <= 1)// compulsory initialization (even for errorprev, needed when dx==dy)errorprev=error=dx; // start in the middle of the squarefor (i=0 ; i<dx ; i++){ // do not use the first point (already done)x+=xstep;
error+=ddy;
if (error>ddx){ // increment y if AFTER the middle ( > )y+=ystep;
error-=ddx;
// three cases (octant == right->right-top for directions below):if (error+errorprev<ddx) // bottom square alsoPOINT (x, y-ystep);
elseif (error+errorprev>ddx) // left square alsoPOINT (x-xstep, y);
else{ // corner: bottom and left squares alsoPOINT (x, y-ystep);
POINT (x-xstep, y);
}
}
POINT (x, y);
errorprev=error;
}
}else{ // the same as aboveerrorprev=error=dy;
for (i=0 ; i<dy ; i++){
y+=ystep;
error+=ddx;
if (error>ddy){
x+=xstep;
error-=ddy;
if (error+errorprev<ddy)
POINT (x-xstep, y);
elseif (error+errorprev>ddy)
POINT (x, y-ystep);
else{
POINT (x-xstep, y);
POINT (x, y-ystep);
}
}
POINT (x, y);
errorprev=error;
}
}
// assert ((y == y2) && (x == x2)); // the last point (y2,x2) has to be the same with the last point of the algorithm
}
The text was updated successfully, but these errors were encountered:
Let user draw more tiles per click
Hint: Use Bresenham Algorithm as in http://eugen.dedu.free.fr/projects/bresenham/
The text was updated successfully, but these errors were encountered: