/* Filename: AnimatedSprite.cpp * * Author: Br. Isidore Minerd * * Date: August 11, 2009 * * Description: This simple little program draws a Sierpinski * Gasket, a simple type of fractal. More information * on it can be found at: * http://mathworld.wolfram.com/SierpinskiSieve.html * http://en.wikipedia.org/wiki/Sierpinski_triangle * * This program uses the "Chaos Game" algorithm to * render the Sierpinski Gasket. */ #include "DarkGDK.h" // Used to determine the granularity of the image const int NumSierpinskiPoints = 25000; void DarkGDK ( void ) { dbSetWindowTitle("Sierpinski Gasket Example"); // Initialize two parallel arrays with points for an equilateral triangle // e.g. Point0 => (pointsX[0],pointsY[0]) double pointsX[3]={120,520,320},pointsY[3]={400,400,53.59}; // Use the first point on the triangle as our starting point // There are other cases we could investigate but not now int currentPointX=120,currentPointY=400,randomPointIndex,numPoints = 0; dbRandomize(dbTimer()); while(LoopGDK() && numPoints < NumSierpinskiPoints) { // Select a random vertex randomPointIndex = dbRND(2); // Find the distance half-way between that vertex and our current point currentPointX = (pointsX[randomPointIndex] + currentPointX) / 2; currentPointY = (pointsY[randomPointIndex] + currentPointY) / 2; // draw the resulting point dbDot(currentPointX,currentPointY); numPoints++; } // If the user did not escape out already, let the screen sit. dbWaitKey(); return; }