50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
#include "graphics.h"
|
|
#include "utils.h"
|
|
#include <SDL2/SDL_render.h>
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
|
|
using namespace Mandelbrot;
|
|
|
|
Graphics::Graphics(int w, int h, std::string title) : w(w), h(h), title(title)
|
|
{
|
|
SDL_Window *window = SDL_CreateWindow(this->title.c_str(),
|
|
SDL_WINDOWPOS_CENTERED,
|
|
SDL_WINDOWPOS_CENTERED,
|
|
this->w, this->h, 0);
|
|
|
|
if (!window)
|
|
{
|
|
std::cout << "Could not create window. "
|
|
<< SDL_GetError() << std::endl;
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
this->window = window;
|
|
|
|
SDL_Renderer *r = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
|
|
|
if (!r)
|
|
{
|
|
std::cout << "Could not create renderer. "
|
|
<< SDL_GetError() << std::endl;
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
this->renderer = r;
|
|
}
|
|
|
|
void Graphics::drawPoint(const Vec2i &pos, const rgb &col)
|
|
{
|
|
SDL_RenderDrawPoint(this->renderer, pos.x, pos.y);
|
|
}
|
|
|
|
void Graphics::plot(const Vec2bf &from, const Vec2bf &to)
|
|
{
|
|
for (double i = 0.0; i < this->w; i++) {
|
|
for (double j = 0.0; j < this->h; j++) {
|
|
BigFloat f = (from.x - to.x) * from.x + (i / this->w);
|
|
}
|
|
}
|
|
}
|