0% found this document useful (0 votes)
10 views3 pages

2345

The document contains a C++ program that implements a simple graphics application for clipping a line segment within a defined rectangular window. It prompts the user to input the coordinates for the window and the endpoints of the line segment, calculates the clipping codes for both points, and displays the line before and after clipping. The program utilizes the graphics.h library for rendering the graphics and handling user input.

Uploaded by

9iraj.jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

2345

The document contains a C++ program that implements a simple graphics application for clipping a line segment within a defined rectangular window. It prompts the user to input the coordinates for the window and the endpoints of the line segment, calculates the clipping codes for both points, and displays the line before and after clipping. The program utilizes the graphics.h library for rendering the graphics and handling user input.

Uploaded by

9iraj.jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <iostream>

#include <conio.h>
#include <graphics.h>
using namespace std;

int main() {
int gd = DETECT, gm;

static int xmin, ymin, xmax, ymax;


cout << "Enter the coordinates for your window: "
<< endl;
cout << "x min: "; cin >> xmin;
cout << "y min: "; cin >> ymin;
cout << "x max: "; cin >> xmax;
cout << "y max: "; cin >> ymax;

static int x1, y1, x2, y2;


cout << "Enter the coordinates for your window: "
<< endl;
cout << "x1: "; cin >> x1;
cout << "y1: "; cin >> y1;
cout << "x2: "; cin >> x2;
cout << "y2: "; cin >> y2;

int block_code[2][4] = {0};

//for point 1
if(x1 < xmin) block_code[0][3] = 1;
if(x1 > xmax) block_code[0][2] = 1;
if(y1 < ymin) block_code[0][1] = 1;
if(y1 > ymax) block_code[0][0] = 1;

//for point 2
if(x2 < xmin) block_code[1][3] = 1;
if(x2 > xmax) block_code[1][2] = 1;
if(y2 < ymin) block_code[1][1] = 1;
if(y2 > ymax) block_code[1][0] = 1;

//block code for both points


cout << "Point 1: " << block_code[0][0] <<
block_code[0][1] << block_code[0][2] <<
block_code[0][3] << endl;
cout << "Point 2: " << block_code[1][0] <<
block_code[1][1] << block_code[1][2] <<
block_code[1][3] << endl;

initgraph(&gd, &gm, NULL);


outtextxy(100, 50, "Before Clipping: ");
rectangle(xmin, ymin, xmax, ymax);
line(x1, y1, x2, y2);
delay(10000);
cleardevice();

//After Clipping

outtextxy(100, 50, "After Clipping: ");


rectangle(xmin, ymin, xmax, ymax);

if(x1 < xmin) x1 = xmin;


if(x1 > xmax) x1 = xmax;
if(y1 < ymin) y1 = ymin;
if(y1 > ymax) y1 = ymax;

if(x2 < xmin) x2 = xmin;


if(x2 > xmax) x2 = xmax;
if(y2 < ymin) y2 = ymin;
if(y2 > ymax) y2 = ymax;
line(x1, y1, x2, y2);
getch();
closegraph();

return 0;
}

You might also like