MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
sierpinski_triangle.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file sierpinski_triangle.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief This little program draws a S. Gasket using an iterative, random algorithm.@EOL
7 @std C++20
8 @copyright
9 @parblock
10 Copyright (c) 1988-2015, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
11
12 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
13
14 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
15
16 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
18
19 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
20 without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 DAMAGE.
28 @endparblock
29*/
30/*******************************************************************************************************************************************************.H.E.**/
31/** @cond exj */
32
33//--------------------------------------------------------------------------------------------------------------------------------------------------------------
34#include "ramCanvas.hpp"
35
36//--------------------------------------------------------------------------------------------------------------------------------------------------------------
37typedef double PointType[2];
38
39//--------------------------------------------------------------------------------------------------------------------------------------------------------------
40int main() {
41 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
42 PointType cpt = {0.0, 0.0};
43 mjr::ramCanvas3c8b::colorType aColor[] = { mjr::ramCanvas3c8b::colorType(255, 0, 0), mjr::ramCanvas3c8b::colorType(0, 255, 0), mjr::ramCanvas3c8b::colorType(0, 0, 255) };
44 PointType pts[] = {{0.0, 0.8}, {-0.8, -0.8}, {0.8, -0.8}};
45 int NumPts = 3;
46
47 mjr::ramCanvas3c8b theRamCanvas(2048, 2048, -1, 1, -1, 1);
48 for(int n=0;n<10000000;n++) {
49 int ip = rand()%NumPts;
50 cpt[0] = (pts[ip][0] + cpt[0]) / 2.0;
51 cpt[1] = (pts[ip][1] + cpt[1]) / 2.0;
52 if(n > 100000)
53 theRamCanvas.drawPoint(cpt[0], cpt[1], aColor[ip]);
54 }
55 theRamCanvas.writeTIFFfile("sierpinski_triangle.tiff");
56
57 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
58 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
59
60 return 0;
61}
62/** @endcond */
int main(int argc, char *argv[])