Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AakashCode12/743755be06f62560aaa9680a85483b0c to your computer and use it in GitHub Desktop.
Save AakashCode12/743755be06f62560aaa9680a85483b0c to your computer and use it in GitHub Desktop.
#include <iostream.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <dos.h>
#include <graphics.h>
//todo Fractal Triangle
int fractalTriangle(double x1, double y1, double x2, double y2, double x3, double y3, int c);
int fractalTriangle(double x1, double y1, double x2, double y2, double x3, double y3, int c)
{
c++;
if (c == 8)
{
return 2;
}
line((x1 + x2) / 2, (y1 + y2) / 2, (x2 + x3) / 2, (y2 + y3) / 2);
line((x2 + x3) / 2, (y2 + y3) / 2, (x1 + x3) / 2, (y1 + y3) / 2);
line((x1 + x2) / 2, (y1 + y2) / 2, (x1 + x3) / 2, (y1 + y3) / 2);
fractalTriangle(x1, y1, (x1 + x2) / 2, (y1 + y2) / 2, (x1 + x3) / 2, (y1 + y3) / 2, c);
fractalTriangle(x2, y2, (x1 + x2) / 2, (y1 + y2) / 2, (x2 + x3) / 2, (y2 + y3) / 2, c);
fractalTriangle(x3, y3, (x1 + x3) / 2, (y1 + y3) / 2, (x2 + x3) / 2, (y2 + y3) / 2, c);
}
void main()
{
clrscr();
int gd = DETECT, gm;
double x1, y1, x2, y2, x3, y3;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
cleardevice();
cout << "The Fractal Triangle";
cout << "Enter the 3 Vertices of Triangle as (x,y)\n";
cin >> x1 >> y1;
cin >> x2 >> y2;
cin >> x3 >> y3;
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
line(x3, y3, x1, y1);
fractalTriangle(x1, y1, x2, y2, x3, y3, 0);
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment