15个版本
0.2.4 | 2024年3月11日 |
---|---|
0.2.3 | 2024年3月10日 |
0.1.9 | 2024年3月6日 |
#477 在 图像
每月下载量:179
12KB
240 代码行
Fenpix库
Fenpix是一个将FEN字符串转换为像素棋盘的Rust库。
像素资源由我设计,所以您可以自由地按照自己的喜好使用它们。
功能
fen_to_board_image
将fen字符串(例如:"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")转换为像素艺术棋盘。
fen_to_board_buffer
将fen字符串转换为棋盘图像缓冲区。
使用方法
使用它非常简单。
// Import the library.
use fenix::*;
// The function `fen_to_board_img` takes four parameters:
// 1. The FEN string
// 2. The image output directory
// 3. The upscale multiplier
// 4. The ChessAssets instance
// This returns an result(), or an error if it fails to convert the fen to image.
// The board also auto rotates depending on whose turn it is.
let result = fen_to_board_img("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w", "chess_board.png", 1, ChessAssets::default());
result.unwrap();
// The function `fen_to_board_buffer` also takes three parameters:
// 1. The FEN string
// 2. The upscale multiplier
// 3. The ChessAssets instance
// This returns an result type that needs to be matched or unwrapped.
// The board also auto rotates depending on whose turn it is.
let img_buffer = fen_to_board_buffer("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR b", 1, ChessAssets::default()).unwrap();
// The above functions are inefficient because they load all the chess assets every time they are called.
// For better performance, load the assets once and store them in a variable.
fn main() {
let assets = ChessAssets::default();
loop {
fen_to_board_img("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w", "chess_board.png", 1, &assets).unwrap();
let img_buffer = fen_to_board_buffer("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR b", 1, &assets).unwrap();
}
}
依赖关系
~5MB
~60K SLoC