mandelbrot/main.cpp
2022-07-19 20:43:56 +02:00

76 lines
2.1 KiB
C++

/*
The GPLv3 License (GPLv3)
Copyright (c) 2022 Akos Horvath
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <unistd.h>
#include "graphics.h"
using namespace Mandelbrot;
int main(int argc, char **argv)
{
char c;
std::string targ, iarg;
int tcount = 0;
int maxiter = 0;
while ((c = getopt(argc, argv, "t::i::")) != -1) {
switch (c) {
case 't':
targ = optarg;
break;
case 'i':
iarg = optarg;
break;
case ':':
std::cout << "option needs a value." << std::endl;
exit(1);
case '?':
if (optopt == 't' || optopt == 'i')
fprintf(stderr, "Option -%c requires an argument.\n",
optopt);
else if (isprint (optopt))
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf(stderr,
"Unknown option character `\\x%x'.\n",
optopt);
exit(1);
}
}
try {
tcount = std::stoi(targ);
maxiter = std::stoi(iarg);
} catch(...) {
std::cout << "Invalid arguments." << std::endl;
exit(1);
}
if (tcount == 0 || tcount < 0)
tcount = 4;
if (maxiter == 0 || maxiter < 0)
maxiter = 100;
Graphics g = Graphics(1800, 1200, "Mandelbrot set visualizer", tcount, maxiter);
g.mainLoop();
return 0;
}