feat: add support for color and buffer shading
This commit is contained in:
@@ -1,34 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include "vec.hpp"
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
|
||||
#include <functional>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <vector>
|
||||
|
||||
struct Screen {
|
||||
char *buf;
|
||||
/**
|
||||
* Unit pixel information struct
|
||||
*/
|
||||
struct Symbol {
|
||||
char sym;
|
||||
vec<3> color = {0,0,0};
|
||||
bool visible = true;
|
||||
|
||||
Symbol &operator=(char c) { sym = c; return *this; };
|
||||
};
|
||||
|
||||
/**
|
||||
* Function taking screen coords and space coords and returning a Symbol for
|
||||
* that position
|
||||
*/
|
||||
using char_shader_t = std::function<Symbol(int, int, float, float)>;
|
||||
|
||||
std::size_t w, h;
|
||||
|
||||
float dx = 0, dy = 0;
|
||||
float sx = 1, sy = 1;
|
||||
float sx = 1, sy = 1.8;
|
||||
|
||||
void draw();
|
||||
void clear();
|
||||
|
||||
char &at(std::size_t n);
|
||||
char &at(std::size_t x, std::size_t y);
|
||||
Symbol &at(std::size_t n);
|
||||
Symbol &at(int x, int y);
|
||||
Symbol &at(float x, float y);
|
||||
|
||||
void resize(std::size_t n);
|
||||
void resize(std::size_t x, std::size_t y);
|
||||
|
||||
std::pair<float, float> screen_to_xy(int w, int h);
|
||||
std::pair<int, int> xy_to_screen(float x, float y);
|
||||
|
||||
Screen(std::size_t n) : buf(nullptr) { resize(n); }
|
||||
Screen(std::size_t x, std::size_t y) : buf(nullptr) { resize(x, y); }
|
||||
~Screen() { delete[] buf; }
|
||||
|
||||
std::vector<const vec<2>*> points;
|
||||
char_shader_t shader;
|
||||
|
||||
private:
|
||||
char _dummy;
|
||||
Symbol *buf;
|
||||
Symbol _dummy;
|
||||
|
||||
static inline void gotoxy(int x, int y)
|
||||
{
|
||||
@@ -36,6 +63,19 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
using colorizer_t = std::function<vec<3>(float)>;
|
||||
|
||||
struct TanhColorizer {
|
||||
float scale = 1.0;
|
||||
float translate = 0.0;
|
||||
vec<3> operator()(float y);
|
||||
|
||||
private:
|
||||
static vec<3> hsl_to_rgb(float h, float s, float l);
|
||||
static float hue_to_rgb(float p, float q, float t);
|
||||
};
|
||||
|
||||
|
||||
static termios old, current;
|
||||
static inline void enter_noncanonical_mode(void)
|
||||
{
|
||||
|
Reference in New Issue
Block a user