16 uint8_t
r = 0,
g = 0,
b = 0,
a = 255;
29 return {c.
r, c.
g, c.
b, c.
a};
32 return {c.
r, c.g, c.b, c.a};
36 return {uint8_t(c >> 24), uint8_t(c >> 16), uint8_t(c >> 8), uint8_t(c)};
41 t = std::clamp(t, 0.0f, 1.0f);
42 return from_rl(ColorFromHSV((1.0f - t) * 240.0f, 1.0f, 0.95f));
47 t = std::clamp(t, -1.0f, 1.0f);
49 auto v = uint8_t(255 * t * t);
50 return {v, 0, uint8_t(v / 10), 255};
52 auto v = uint8_t(255 * t * t);
53 return {uint8_t(v / 10), 0, v, 255};
61 float amp = std::min(1.0f,
float(std::sqrt(prob / max_prob)));
62 float hue = float((phase + 3.14159265) / (2.0 * 3.14159265)) * 360.0f;
63 float h6 = hue / 60.0f;
65 float f = h6 - int(h6);
67 float p = amp * (1.0f - s);
68 float q = amp * (1.0f - s * f);
69 float u = amp * (1.0f - s * (1.0f - f));
103 return {uint8_t(r * 255), uint8_t(g * 255), uint8_t(b * 255), 255};
107 t = std::clamp(t, 0.0f, 1.0f);
109 uint8_t(a.
r + t * (b.
r - a.
r)),
110 uint8_t(a.
g + t * (b.
g - a.
g)),
111 uint8_t(a.
b + t * (b.
b - a.
b)),
112 uint8_t(a.
a + t * (b.
a - a.
a)),
129 buf.assign(n * n, ::BLACK);
130 Image img = GenImageColor(n, n, ::BLACK);
131 tex = LoadTextureFromImage(img);
172 void dot(
float x,
float y,
Color c,
float r = 3.0f) {
173 DrawCircleV({x, y}, r,
to_rl(c));
176 DrawCircleLines(
int(x),
int(y), r,
to_rl(c));
178 void line(
float x0,
float y0,
float x1,
float y1,
Color c,
float thick = 1.0f) {
179 DrawLineEx({x0, y0}, {x1, y1}, thick,
to_rl(c));
181 void rect(
float x,
float y,
float w,
float h,
Color c) {
182 DrawRectangleV({x, y}, {w, h},
to_rl(c));
185 DrawRectangleLinesEx({x, y, w, h}, thick,
to_rl(c));
187 void text(
const char* s,
float x,
float y,
int sz,
Color c) {
188 DrawText(s,
int(x),
int(y), sz,
to_rl(c));
192 void textf(
float x,
float y,
int sz,
Color c,
const char* fmt, ...) {
196 vsnprintf(buf,
sizeof(buf), fmt, args);
198 DrawText(buf,
int(x),
int(y), sz,
to_rl(c));
206 for (
int row = 0; row < N; ++row)
207 for (
int col = 0; col < N; ++col)
208 cv.buf[row * N + col] =
to_rl(color_fn(col, row));
209 UpdateTexture(cv.tex, cv.buf.data());
210 DrawTexturePro(cv.tex,
211 {0, 0, float(N), float(N)},
212 {0, 0, float(width), float(height)},
220 void slider(
const char* label,
double lo,
double hi,
double& val) {
221 constexpr int PAD = 10;
222 constexpr int SLOT_H = 38;
223 constexpr int BAR_W = 220;
224 constexpr int BAR_H = 8;
229 DrawRectangle(X - 4, Y - 2, BAR_W + 8, SLOT_H - 4, {0, 0, 0, 170});
230 DrawRectangle(X, Y + 18, BAR_W, BAR_H, {80, 80, 80, 220});
232 float t = std::clamp(
float((val - lo) / (hi - lo)), 0.0f, 1.0f);
233 int tx = X + int(t * BAR_W);
235 Vector2 mp = GetMousePosition();
236 Rectangle hit = {float(X), float(Y), float(BAR_W), float(SLOT_H)};
237 if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) && CheckCollisionPointRec(mp, hit)) {
238 t = std::clamp((mp.x - X) / BAR_W, 0.0f, 1.0f);
239 val = lo + t * (hi - lo);
240 tx = X + int(t * BAR_W);
243 DrawCircle(tx, Y + 18 + BAR_H / 2, 9, {200, 200, 200, 240});
244 DrawText(TextFormat(
"%s: %.3g", label, val), X, Y + 2, 13, {210, 210, 210, 230});
259 c.position = {cam.
px, cam.
py, cam.
pz};
260 c.target = {cam.
tx, cam.
ty, cam.
tz};
261 c.up = {cam.
ux, cam.
uy, cam.
uz};
263 c.projection = CAMERA_PERSPECTIVE;
269 DrawSphere({x, y, z}, r,
to_rl(c));
272 DrawSphereWires({x, y, z}, r, 6, 6,
to_rl(c));
274 void line3d(
float x0,
float y0,
float z0,
float x1,
float y1,
float z1,
Color c) {
275 DrawLine3D({x0, y0, z0}, {x1, y1, z1},
to_rl(c));
277 void cube3d(
float x,
float y,
float z,
float sx,
float sy,
float sz,
Color c) {
278 DrawCube({x, y, z}, sx, sy, sz,
to_rl(c));
289template<
class DrawFn>
290void run(
const char* title,
int w,
int h, DrawFn draw,
Color bg = {15, 15, 15, 255}) {
291 SetConfigFlags(FLAG_MSAA_4X_HINT);
292 InitWindow(w, h, title);
296 Frame frame{w, h, state.paused, state.substeps, state};
298 while (!WindowShouldClose()) {
299 if (IsKeyPressed(KEY_SPACE))
300 state.paused = !state.paused;
301 if (IsKeyPressed(KEY_EQUAL) || IsKeyPressed(KEY_KP_ADD))
302 state.substeps = std::min(state.substeps + 1, 16);
303 if (IsKeyPressed(KEY_MINUS) || IsKeyPressed(KEY_KP_SUBTRACT))
304 state.substeps = std::max(state.substeps - 1, 1);
306 state.slider_count = 0;
309 ClearBackground(
to_rl(bg));
314 DrawRectangle(w / 2 - 70, h / 2 - 18, 140, 36, {0, 0, 0, 160});
315 DrawText(
"PAUSED", w / 2 - 46, h / 2 - 10, 24, ::YELLOW);
321 state.canvas.unload();
Color lerp_color(Color a, Color b, float t)
void run(const char *title, int w, int h, DrawFn draw, Color bg={15, 15, 15, 255})
Color phase_hsv_color(double prob, double phase, double max_prob)
Phase/probability colormap for quantum wavefunctions.
Color heat_color(float t)
Heat colormap for .
Color diverging_color(float t)
Diverging colormap for .
inline ::Color to_rl(Color c)
void dot(float x, float y, Color c, float r=3.0f)
void line(float x0, float y0, float x1, float y1, Color c, float thick=1.0f)
void field(int N, Fn color_fn)
void sphere3d_wire(float x, float y, float z, float r, Color c)
void cube3d(float x, float y, float z, float sx, float sy, float sz, Color c)
void rect_outline(float x, float y, float w, float h, Color c, float thick=1.0f)
void slider(const char *label, double lo, double hi, double &val)
void line3d(float x0, float y0, float z0, float x1, float y1, float z1, Color c)
bool reset_pressed() const
void textf(float x, float y, int sz, Color c, const char *fmt,...)
void sphere3d(float x, float y, float z, float r, Color c)
void text(const char *s, float x, float y, int sz, Color c)
void circle(float x, float y, float r, Color c)
void rect(float x, float y, float w, float h, Color c)
std::vector<::Color > buf