Practical 12
Practical 12
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
while (1)
{
if ((code0 == 0) && (code1 == 0))
{
// Both points inside the clipping window
accept = 1;
break;
}
else if (code0 & code1)
{
break;
} else {
// Calculate the intersection point
int code_out;
float x, y;
if (code0 != 0)
code_out = code0;
else
code_out code1;
// Find the intersection point
if (code_out & ABOVE)
{ x = x0+ (x1-x0) (y_max-y0)/(y1-y0); y = y_max;
} else if (code_out & BELOW)
{ x = x0+ (x1-x0) (y_miny0)/(y1-y0);
y = y_min; }
else if (code_out & RIGHT)
{ y=y0+(y1-y0) (x_max-x0)/(x1-x0);
x = x_max;
} else if (code_out & LEFT)
{
y=y0+(y1-y0) (x_minx0)/(x1-x0);
x = x_min;
}
// Update the point outside the clipping window
if (code_out == code0) {
x0 = x;
yo = y;
code0 = computeCode(x0, y0, x_min, x_max, y_min, y_max);
} else {
x1 = x;
y1 = y; code1 = computeCode(x1, y1, x_min, x_max, y_min, y_max);
}
}
}
if (accept)
{
// Draw the accepted line
line((int)x0, (int)y0, (int)x1, (int)y1);
}
}
void main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");