mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-17 08:28:09 +08:00
add pixelate func and example
This commit is contained in:
@@ -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
37
examples/dom/pixelate.cpp
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user