Port AtelierArith/RandomLogos.jl written in Julia to C++.
- CMake
- Julia
$ git clone https://github.com/AtelierArith/CxxRandomLogo.git
$ cd CxxRandomLogo
$ julia -e 'using Pkg; Pkg.activate(); Pkg.add("CxxWrap.jl")'
$ bash build.sh
$ julia --project -e 'using Pkg; Pkg.instantiate()'
Our C++ implementation provides point generation features that can be accessed from generate_points
.
// main.cpp
#include <iostream>
#include <random>
#include "point_generation.hpp"
int main() {
// 100000 points
auto xy = generate_points();
auto xs = xy.first; // x coordinates
auto ys = xy.second; // y coordinates
// header
std::cout << "x,y" << std::endl;
// contents
for (int i = 0; i < xs.size(); i++) {
auto x = xs[i];
auto y = ys[i];
std::cout << x << "," << y << std::endl;
}
return 0;
};
To build our C++ code, just run bash build.sh
.
$ bash build.sh # This script builds our C++ code
We'll see that ./build/bin
is generated and the executable file CxxRandomLogo
corresponds to main.cpp
is generated. To store results as a CSV file, just run the following command:
$ ./build/bin/CxxRandomLogo > out.csv
$ head out.csv
x,y
0,0
-0.380685,0.692171
-1.09698,0.779349
-1.61693,0.45568
0.489574,-0.189705
-0.893767,-0.739919
-0.0128572,-1.12225
-0.594527,-1.4382
-0.226511,-1.66354
We can visalize the result using Julia script named vis.jl
.
$ julia vis.jl # out.png
This generates out.png
$ julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.10.3 (2024-04-30)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> using ImageInTerminal
julia> using CxxRandomLogo: draw
julia> [draw() draw() draw(); draw() draw() draw()]
![image](https://private-user-images.githubusercontent.com/16760547/331805600-f9074553-dd6a-413d-8642-bbb38fe6da49.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEzMTQ4OTIsIm5iZiI6MTcyMTMxNDU5MiwicGF0aCI6Ii8xNjc2MDU0Ny8zMzE4MDU2MDAtZjkwNzQ1NTMtZGQ2YS00MTNkLTg2NDItYmJiMzhmZTZkYTQ5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE4VDE0NTYzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRjNWU2OGMwOGIyZGI1ZGFhMWEyYTdiMzZlNjVmZmQyYTkyNTVkMTI3YTQzN2Y1NTIwYTA1NWZiZjY1ZGFlMjMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.1uU5OvKccn_bZp91SgztMsFkhx-Z-YSC0h5FywXjSv8)
julia> using Pluto; Pluto.run()
Then open playground/pluto/notebook.jl from Pluto Web UI