add license

This commit is contained in:
2022-07-06 19:20:48 +02:00
parent a2d5e86188
commit 00b4c837d0
8 changed files with 894 additions and 17 deletions

View File

@ -1,3 +1,22 @@
/*
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 "graphics.h"
#include "utils.h"
#include <SDL2/SDL_render.h>
@ -44,6 +63,65 @@ void Graphics::drawPoint(const Vec2i &pos, const rgb &col)
SDL_RenderDrawPoint(this->renderer, pos.x, pos.y);
}
rgb hsv2rgb(hsv in)
{
double hh, p, q, t, ff;
long i;
rgb out;
if(in.s <= 0.0) { // < is bogus, just shuts up warnings
out.r = in.v;
out.g = in.v;
out.b = in.v;
return out;
}
hh = in.h;
if(hh >= 360.0) hh = 0.0;
hh /= 60.0;
i = (long)hh;
ff = hh - i;
p = in.v * (1.0 - in.s);
q = in.v * (1.0 - (in.s * ff));
t = in.v * (1.0 - (in.s * (1.0 - ff)));
switch(i) {
case 0:
out.r = in.v;
out.g = t;
out.b = p;
break;
case 1:
out.r = q;
out.g = in.v;
out.b = p;
break;
case 2:
out.r = p;
out.g = in.v;
out.b = t;
break;
case 3:
out.r = p;
out.g = q;
out.b = in.v;
break;
case 4:
out.r = t;
out.g = p;
out.b = in.v;
break;
case 5:
default:
out.r = in.v;
out.g = p;
out.b = q;
break;
}
//std::cout << "ret" << out.g << out.b << out.b << std::endl;
return out;
}
void Graphics::plot(Mandelbrotc const &m)
{
// std::vector<uint8_t> screen = std::vector<uint8_t>();
@ -112,8 +190,19 @@ void Graphics::plot(Mandelbrotc const &m)
for (uint32_t i = 0; i < m.s.x; i++) {
for (uint32_t j = 0; j < m.s.y; j++) {
uint8_t color = 255 - (m.screen[i][j]*255/m.max_iter);
SDL_SetRenderDrawColor(this->renderer, color, color, color, 255);
//uint8_t color = 255 - (m.screen[i][j]*255/m.max_iter);
uint8_t iter = m.screen[i][j];
hsv h;
h.h = 255*(double)iter/(double)m.max_iter;
h.s = 255;
if (iter < m. max_iter)
h.v = 255;
else
h.v = 0;
rgb r;
r = hsv2rgb(h);
//std::cout << "rgb" << r.r << r.g << r.b << std::endl;
SDL_SetRenderDrawColor(this->renderer, r.r, r.g, r.b, 255);
SDL_RenderDrawPoint(renderer, (int)i, (int)j);
}
}
@ -221,9 +310,7 @@ void Graphics::mainLoop()
SDL_SetRenderDrawColor(this->renderer, 255, 255, 255, 255);
SDL_RenderClear(renderer);
SDL_Delay(100);
if (m.done)
exit(1);
SDL_Delay(10);
}
m.stop_threads();
}