# Simple Cantor Thing, version:0.0.0

Apr 22nd, 2021
1,423
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. namespace ct_cantor
2. {
3.     void cantor(
4.         ct::plot::cairo::plot_2d& plot,
5.         unsigned long ri,
6.         unsigned long rn,
7.         glm::vec3 p0,
8.         glm::vec3 p1,
9.         float scale
10.     ) {
11.         if (ri >= rn) return;
12.
13.         glm::vec3 dif = p1 - p0;
14.         glm::vec3 perp = { -dif.y, dif.x, 0.f };
15.
16.         glm::vec3 cp0 = p0 + perp * scale;
17.         glm::vec3 cp1 = p1 + perp * scale;
18.
19.         glm::vec3 cp2 = cp0 + dif * scale;
20.         glm::vec3 cp3 = cp1 - dif * scale;
21.
22.         plot.line(p0, p1, CT_RGBF(1, 1, 0), 4.f);
23.
24.         plot.line(p0, cp0, CT_RGBF(1, 0, 0), 4.f);
25.         plot.line(p1, cp1, CT_RGBF(1, 0, 0), 4.f);
26.         plot.line(cp0, cp2, CT_RGBF(1, 0, 0), 4.f);
27.         plot.line(cp3, cp1, CT_RGBF(1, 0, 0), 4.f);
28.
29.         cantor(plot, ri + 1, rn, p0, cp0, scale);
30.         cantor(plot, ri + 1, rn, p1, cp1, scale);
31.         cantor(plot, ri + 1, rn, cp0, cp2, scale);
32.         cantor(plot, ri + 1, rn, cp3, cp1, scale);
33.
34.         cantor(plot, ri + 1, rn, cp0, p0, scale);
35.         cantor(plot, ri + 1, rn, cp1, p1, scale);
36.         cantor(plot, ri + 1, rn, cp2, cp0, scale);
37.         cantor(plot, ri + 1, rn, cp1, cp3, scale);
38.     }
39.
40.
41.     void manifest(ct::plot::cairo::plot_2d& plot)
42.     {
43.         std::cout << "ct_cantor::manifest\n\n";
44.
45.         plot.line({ -1, 0 }, { 1, 0 }, CT_RGBF(1, 0, 0), 4.f);
46.
47.         cantor(plot, 0, 5, { -1, 0, 0 }, { 1, 1, 0 }, 1.f / 3.f);
48.         cantor(plot, 0, 5, { 1, 0, 0 }, { -1, -.5, 0 }, 1.f / 3.f);
49.     }
50. };
RAW Paste Data