Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <graphics.h>
- #include <iostream.h>
- #include <math.h>
- #include <conio.h>
- #include <fstream.h>
- #include <iomanip.h>
- void main()
- {
- int x1, y1, x2, y2;
- int gdriver = DETECT, gmode;
- clrscr();
- cout << "Enter the coordinates : ";
- cout << "\nx1 : ";
- cin >> x1;
- cout << "\ny1 : ";
- cin >> y1;
- cout << "\nx2 : ";
- cin >> x2;
- cout << "\ny2 : ";
- cin >> y2;
- int dx = abs(x1 - x2), dy = abs(y1 - y2);
- int p = 2 * dy - dx;
- int twoDy = 2 * dy, twoDyDx = 2 * (dy - dx);
- int x, y, xEnd;
- cout << "\nSlope is : " << (float)dy/dx;
- if((((float)dy/dx) >= 1) || (((float)dy/dx) == 0))
- {
- cout << "\nSlope m must be 0 < m < 1";
- getch();
- return;
- }
- int StoreX[50], StoreY[50], i = 1;
- cout << "\nPress Enter to continue...";
- getch();
- initgraph(&gdriver, &gmode, "F:\\TC\\BGI");
- if(x1 > x2)
- {
- x = x2;
- y = y2;
- xEnd = x1;
- }
- else
- {
- x = x1;
- y = y1;
- xEnd = x2;
- }
- StoreX[0] = x;
- StoreY[0] = y;
- putpixel(x, y, RED);
- while(x < xEnd)
- {
- x++;
- if(p < 0)
- p += twoDy;
- else
- {
- y++;
- p += twoDyDx;
- }
- StoreX[i] = x;
- StoreY[i] = y;
- i++;
- putpixel(x, y, RED);
- }
- outtextxy(100, 10, "Press Enter pls");
- getch();
- closegraph();
- ofstream fout;
- fout.open("Bresen.txt");
- for(int k = 0; k < i; k++)
- {
- fout << StoreX[k] << setw(2) << StoreY[k] << endl;
- }
- fout.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement