MCPcopy Create free account
hub / github.com/AnswerDotAI/gpu.cpp / rasterize

Function rasterize

experimental/tui.h:36–61  ·  view source on GitHub ↗

double pendulum rasterizer

Source from the content-addressed store, hash-verified

34
35// double pendulum rasterizer
36void rasterize(float *pos, size_t n, float maxX, float maxY, std::string &screen,
37 size_t screenWidth, size_t screenHeight) {
38 static const char intensity[] = " .`'^-+=*x17X$8#%@";
39 const size_t eps = 1;
40 // maximum number of simulations to display on the screen
41 const size_t nShow = std::min(static_cast<int>(n), 2000);
42 for (size_t i = 0; i < screenHeight; ++i) {
43 for (size_t j = 0; j < screenWidth - 2; ++j) {
44 int count = 0;
45 for (size_t k = 0; k < 2 * nShow; k += 2) {
46 float nx =
47 (1.0 + pos[k] / maxX) / 2.0 * static_cast<float>(screenWidth);
48 // negate y since it extends from top to bottom
49 float ny = (1.0 - (pos[k + 1] / maxY)) / 2.0 *
50 static_cast<float>(screenHeight);
51 float length = std::sqrt((nx - j) * (nx - j) + (ny - i) * (ny - i));
52 if (length < eps) {
53 count++;
54 }
55 }
56 count = std::min(count / 2, 17); // Need to adjust /2 scaling for different n
57 screen[i * screenWidth + j] = intensity[count];
58 }
59 screen[i * screenWidth + screenWidth - 1] = '\n';
60 }
61}
62
63
64

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected