You are on page 1of 4

ASSIGNMENT 3

NAME-Rutik Kishor Rokade

Roll n0-205B060

PROGRAM

#include<iostream>
#include<graphics.h>
#include<math.h>
using namespace std;

class ddaLine {
public:
void drawLine(int x1, int y1, int x2, int y2);
};

void ddaLine::drawLine(int x1, int y1, int x2, int y2) {


float dx, dy;
dx = (x2 - x1);
dy = (y2 - y1);
int i = 1;
int length;
if (abs(x2 - x1) >= abs(y2 - y1))
length = abs(x2 - x1);
else
length = abs(y2 - y1);
dx = dx / length;
dy = dy / length;
float x, y;
x = x1 + 0.5;
y = y1 + 0.5;
putpixel(x, y, RED);
while (i < length) {
x = x + dx;
y = y + dy;
i++;
delay(100);
putpixel(x, y, RED);
}
return;
}

class circle {
public:
void drawCirc(int x, int y, int r);

void putPix(int x, int y, int xo, int yo) {


putpixel(x + xo, y + yo, 10);
putpixel(-x + xo, -y + yo, 10);
putpixel(-x + xo, y + yo, 10);
putpixel(x + xo, -y + yo, 10);
putpixel(y + xo, x + yo, 10);
putpixel(-y + xo, -x + yo, 10);
putpixel(-y + xo, x + yo, 10);
putpixel(y + xo, -x + yo, 10);

}
};

void circle::drawCirc(int xo, int yo, int r) {


circle c;
int x = 0;
int y = r;
float d = 3 - 2 * r;
c.putPix(x, y, xo, yo);
while (x <= y) {
if (d < 0) {
d = d + 4 * x + 6;
} else if (d >= 0) {
d = d + 4 * (x - y) + 10;
y = y - 1;
}
x = x + 1;
delay(100);
c.putPix(x, y, xo, yo);
}
}

class tri : public ddaLine, public circle {


public:
int x[3];
int y[3];
int h;

tri(int p, int q, int l) {


x[0] = p;
y[0] = q;
x[1] = x[0] + l;
y[1] = y[0];
x[2] = x[0]+(l / 2);
h = (sqrt(l * l - (l * l / 4)));
y[2] = y[0] + h;
for (int i = 0; i < 3; i++) {
cout << "\n" << x[i] << " " << y[i];
}
}
void draw();
};

void tri::draw() {
ddaLine L;
circle C;
L.drawLine(x[0], y[0], x[1], y[1]);
L.drawLine(x[2], y[2], x[1], y[1]);
L.drawLine(x[0], y[0], x[2], y[2]);
C.drawCirc(x[2], (y[0]+(h / 3)), (h / 3));
C.drawCirc(x[2], (y[0]+(h / 3)), (2 * h / 3));
}

int main() {
int l, x, y;
cout << "Enter Length of Equilateral Triangle: ";
cin>>l;
cout << "\nEnter starting pt.";
cin >> x>>y;
int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
tri t(x, y, l);
t.draw();
delay(100000);
closegraph();
return 0;
}

OUTPUT:

Enter Length of Equilateral Triangle: 60

Enter starting pt.20

20

20 20

80 20

50 71

--------------------------------
Process exited after 140.4 seconds with return value 0

Press any key to continue . . .

You might also like