MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
heart2022.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file heart2022.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw a heart for Valentines Day 2022.@EOL
7 @keywords
8 @std C++20
9 @copyright
10 @parblock
11 Copyright (c) 1988-2015, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
14
15 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
16
17 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19
20 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
21 without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 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
28 DAMAGE.
29 @endparblock
30*/
31/*******************************************************************************************************************************************************.H.E.**/
32/** @cond exj */
33
34//--------------------------------------------------------------------------------------------------------------------------------------------------------------
35#include "ramCanvas.hpp"
36
37//--------------------------------------------------------------------------------------------------------------------------------------------------------------
38double f(double x, double y) {
39 return std::pow(x, 2) * std::pow(y, 3) - std::pow(std::pow(x, 2) + std::pow(y, 2) - 1, 3);
40}
41
42//--------------------------------------------------------------------------------------------------------------------------------------------------------------
43int main(void) {
44 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
45 int x, y;
46 double maxH = std::hypot(512, 512);
47 mjr::ramCanvas3c8b theRamCanvas(1024, 1024, -2, 2, -2, 2);
48
49 for(y=0;y<theRamCanvas.getNumPixY();y++)
50 for(x=0;x<theRamCanvas.getNumPixX();x++) {
51 if(f(theRamCanvas.int2realX(x), theRamCanvas.int2realY(y)) > 0)
52 theRamCanvas.drawPoint(x, y, "red");
53 else
54 theRamCanvas.drawPoint(x, y, mjr::color3c8b::csPLYquad::c(mjr::math::linm::gen_map(std::hypot(x-512, y-512), maxH, 0.0, 0.5, 1.0)));
55 }
56
57 theRamCanvas.drawString("MWU. M", mjr::hershey::font::ROMAN_SL_SANSERIF, 900, 90, "red", 1, 20);
58 theRamCanvas.drawString("2022 ", mjr::hershey::font::ROMAN_SL_SANSERIF, 900, 60, "red", 1, 20);
59 theRamCanvas.drawString(" -m", mjr::hershey::font::ROMAN_SL_SANSERIF, 900, 30, "red", 1, 20);
60
61 theRamCanvas.writeTIFFfile("heart2022.tiff");
62 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
63 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
64}
65/** @endcond */
int main(int argc, char *argv[])