/******************************************************************** File: sierpinski.cc Author: Dana Vrajitoru Based on the example provided in E. Angel, Interactive Computer Graphics. Project: An implementation of the Sierpinski gasket. Last updated: January 30, 2017. Drawing a fractal using triangles. ********************************************************************/ #include "glheader.h" #include "interface.h" #include "sierpinski.h" // display one triangle void triangle( Point2 a, Point2 b, Point2 c) { glBegin(GL_TRIANGLES); glVertex2fv(a); glVertex2fv(b); glVertex2fv(c); glEnd(); } // Implementation of the Sierpinski gasket by triangle subdivision // using vertex numbers. void divide_triangle(Point2 a, Point2 b, Point2 c, int m) { Point2 v0, v1, v2; int j; if (m>0) { for(j=0; j<2; j++) v0[j]=(a[j]+b[j])/2; for(j=0; j<2; j++) v1[j]=(a[j]+c[j])/2; for(j=0; j<2; j++) v2[j]=(b[j]+c[j])/2; divide_triangle(a, v0, v1, m-1); divide_triangle(c, v1, v2, m-1); divide_triangle(b, v2, v0, m-1); } else triangle(a,b,c); // draw triangle at end of recursion } // Implementation of the Sierpinski "carpet". void carpet(Point2 start, float width, int m) { // To be implemented by the student }