git.haldean.org dotmatrix / e09bcc4
preeeeetty Haldean Brown 4 years ago
2 changed file(s) with 33 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
0 : main.cpp perspective.hpp |> g++ -ggdb -I/usr/include/eigen3 -std=gnu++11 -lpng main.cpp -o dotmatrix |> dotmatrix
0 : main.cpp perspective.hpp |> g++ -ggdb -O3 -I/usr/include/eigen3 -std=gnu++11 -lpng main.cpp -o dotmatrix |> dotmatrix
11 : dotmatrix |> ./dotmatrix |> output.png
44 #include <png++/png.hpp>
55 #include "perspective.hpp"
66
7 #define IMGSIZE 600
7 #define W 1200
8 #define H 400
89
910 static Eigen::Matrix<uint16_t, Eigen::Dynamic, Eigen::Dynamic> img;
1011 typedef png::basic_rgb_pixel<uint8_t> pixel;
1112
13 //int c[] { 255, 150, 100, 70, 50, 20, 0 };
14 uint8_t c[7][3] {
15 { 0, 0, 40 },
16 { 140, 0, 0 },
17 { 180, 30, 0 },
18 { 200, 140, 0 },
19 { 255, 200, 80 },
20 { 255, 255, 140 },
21 { 255, 255, 240 },
22 };
23
1224 int main() {
13 img.resize(IMGSIZE, IMGSIZE);
25 img.resize(W, H);
1426 img.setZero();
1527
1628 Eigen::Vector3f r3;
1830 size_t i, j;
1931
2032 Eigen::Matrix4f view = lookAt<float>(
21 Eigen::Vector3f(3, 10, 5),
22 Eigen::Vector3f(0, 0, 0),
33 Eigen::Vector3f(2, 6, 3),
34 Eigen::Vector3f(0.75, 0.65, 0),
2335 Eigen::Vector3f(0, 0, 1));
24 Eigen::Matrix4f proj = perspective<float>(M_PI / 3, 1, 0.1, 100);
36 Eigen::Matrix4f proj = perspective<float>(M_PI / 32, 1, 0.1, 100);
2537 Eigen::Matrix4f mvp = proj * view;
2638
27 for (float u = 0; u < 2 * M_PI; u += 0.05)
39 const float step = 0.0002;
40 for (float u = 0; u < 2 * M_PI; u += step)
2841 {
29 for (float v = 0; v < M_PI; v += 0.05)
42 for (float v = 0; v < M_PI; v += step)
3043 {
3144 Eigen::Vector4f h;
3245 h.block(0, 0, 3, 1) =
3447 Eigen::AngleAxisf(v, Eigen::Vector3f::UnitY()) *
3548 Eigen::Vector3f::UnitZ();
3649 h[3] = 1;
37 p = mvp * h;
38 i = size_t(p[0] * 100) + IMGSIZE / 2;
39 j = size_t(p[1] * 100) + IMGSIZE / 2;
40 img(i, j) += 1;
50 p = mvp * 2 * h;
51 i = size_t(p[0] * 100) + W / 2;
52 j = size_t(p[1] * 100) + H / 2;
53 if (i >= 0 && i < img.rows() && j >= 0 && j < img.cols())
54 img(i, j) += 1;
4155 }
4256 }
43 png::image<pixel> out(IMGSIZE, IMGSIZE);
44 for (i = 0; i < IMGSIZE; i++)
57 png::image<pixel> out(W, H);
58 for (i = 0; i < W; i++)
4559 {
46 for (j = 0; j < IMGSIZE; j++)
60 for (j = 0; j < H; j++)
4761 {
48 if (img(i, j))
49 out.set_pixel(i, j, pixel(0, 0, 0));
50 else
51 out.set_pixel(i, j, pixel(0xFF, 0xFF, 0xFF));
62 uint16_t step = img(i, j);
63 if (step > 6)
64 step = 6;
65 out.set_pixel(i, j, pixel(c[step][0], c[step][1], c[step][2]));
5266 }
5367 }
5468 out.write("output.png");