add pixelate func and example

This commit is contained in:
Chimezie-Josias Iwu
2024-06-25 18:36:25 +02:00
parent b28d57086a
commit 91f853431f
5 changed files with 104 additions and 1 deletions

View File

@@ -14,6 +14,10 @@ endfunction(example)
add_subdirectory(component)
add_subdirectory(dom)
# Add the pixelate example
add_executable(pixelate ${CMAKE_CURRENT_SOURCE_DIR}/dom/pixelate.cpp)
target_link_libraries(pixelate PRIVATE dom)
if (EMSCRIPTEN)
string(APPEND CMAKE_EXE_LINKER_FLAGS " -s ALLOW_MEMORY_GROWTH=1")
target_link_options(component PUBLIC "SHELL: -s ALLOW_MEMORY_GROWTH=1")

37
examples/dom/pixelate.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include "ftxui/dom/canvas.hpp"
#include <stdio.h> // for getchar
#include <cmath> // for cos
#include <ftxui/dom/elements.hpp> // for Fit, canvas, operator|, border, Element
#include <ftxui/screen/screen.hpp> // for Pixel, Screen
#include <vector> // for vector, allocator
#include "ftxui/dom/canvas.hpp" // for Canvas
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, Color::Red, Color::Blue, Color::Green, ftxui
using namespace ftxui;
using namespace cv;
int main(int argc, char* argv[]) {
if (argc != 2 && argc != 4) {
std::cerr << "Usage: " << argv[0] << " <image_path> [width] [height]" << std::endl;
return 1;
}
std::string image_path = argv[1];
int width, height;
if (argc == 4) {
width = std::stoi(argv[2]);
height = std::stoi(argv[3]);
} else {
// default-values
width = 100;
height = 50;
}
// call static method
Canvas::DrawImageOnTerminal(image_path, width, height);
return 0;
}