aboutsummaryrefslogtreecommitdiff
path: root/gragl.h
blob: b0082cbb65a3a3b1f1301304f8bef7eb087cff98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef GRAGL_H
#define GRAGL_H

#include <stdint.h>

typedef float ConstColor[];
typedef float *Color;

#define PLOT_AUTO(plot) { .function = plot, .nfuncs = sizeof(plot) / sizeof(Function),  .x = 3, .y = 0, .rsize = 5, .step = 0.001 }
#define FUNC_AUTO(f) { .func = f, .color = AUTO_COLORS[(auto_color_index = (auto_color_index + 1) % 5)], .width = 3 }

static ConstColor COLOR_RED    = { 0.800f, 0.140f, 0.120f, 1.0f };
static ConstColor COLOR_GREEN  = { 0.596f, 0.592f, 0.102f, 1.0f };
static ConstColor COLOR_YELLOW = { 0.843f, 0.600f, 0.129f, 1.0f };
static ConstColor COLOR_BLUE   = { 0.271f, 0.522f, 0.533f, 1.0f };
static ConstColor COLOR_PURPLE = { 0.694f, 0.384f, 0.525f, 1.0f };
static ConstColor COLOR_AQUA   = { 0.408f, 0.616f, 0.416f, 1.0f };
static ConstColor COLOR_BLACK  = { 0.157f, 0.157f, 0.157f, 1.0f };
static ConstColor COLOR_DARKER = { 0.114f, 0.125f, 0.129f, 1.0f };
static ConstColor COLOR_WHITE  = { 0.922f, 0.859f, 0.698f, 1.0f };
static ConstColor COLOR_GRAY   = { 0.659f, 0.600f, 0.518f, 1.0f };

static unsigned auto_color_index = 0;
static Color AUTO_COLORS[] = {
	COLOR_RED,
	COLOR_GREEN,
	COLOR_YELLOW,
	COLOR_BLUE,
	COLOR_PURPLE,
	COLOR_AQUA
};

typedef struct {
	double x;
	double y;
} Point2d;

typedef struct {
	double v;
	uint8_t valid;
} Scalar;

typedef struct {
	Scalar (*func)(double);
	Color color;
	double width;
} Function;

typedef struct {
	unsigned width;
	unsigned height;
	double x;
	double y;
	double rsize;
	double step;
	Function *function;
	unsigned nfuncs;
} Plot2d;

typedef struct {
	Plot2d * plots;
	unsigned n;
	unsigned padding;
} Plot2dGroup;

Plot2dGroup * create_plot2d_group(int num_args, ...);
void free_plot2d_group(Plot2dGroup *);
void plot(Plot2dGroup *);

#endif