10个稳定版本
2.0.0 | 2023年12月6日 |
---|---|
1.2.1 | 2023年8月11日 |
1.2.0 | 2023年6月30日 |
1.1.4 | 2023年3月23日 |
1.0.0 | 2022年7月2日 |
#41 in 渲染
在4个crate(直接使用2个)中使用
37KB
735 代码行
wizdraw
- 一个小型no_std crate,用于填充和描边复合贝塞尔曲线(SIMD/SSAA)
限制
- 像素是[R, G, B, A]值的8位分量
- 点坐标是
f32
对的组合
特性
simd
: 包含SIMD代码,在启用抗锯齿时可以提高渲染速度。stroke
: 包含util::stroke_path
实用函数。
默认情况下,此crate不使用SIMD,因为这需要一个nightly工具链。
示例
use wizdraw::{Canvas, Color, CubicBezier, Point, SsaaConfig, util};
use wizdraw::rgb::ComponentBytes;
// size of our output buffer: 1000x1000px
let mut canvas = Canvas::new(1000, 1000);
// the unit for these coordinates is a pixel
let path = [
CubicBezier {
c1: Point::new(250.0, 600.0),
c2: Point::new(250.0, 250.0),
c3: Point::new(750.0, 250.0),
c4: Point::new(750.0, 600.0),
},
CubicBezier {
c1: Point::new(750.0, 600.0),
c2: Point::new(750.0, 400.0),
c3: Point::new(250.0, 400.0),
c4: Point::new(250.0, 600.0),
},
];
// We'll generate another path which represents a line along the other path
let mut contour = Vec::new();
let stroke_width = 10.0; // px
let max_error = 1.0; // px
util::stroke_path(&path, stroke_width, &mut contour, max_error);
// use SIMD functions, if this wizdraw build has the feature
let try_to_use_simd = true;
// we'll use the highest SSAA config
let ssaa = SsaaConfig::X16;
// path holes won't show up on the output
let dont_show_holes = false;
// fill the path with a rainbow texture
canvas.fill(&path, util::rainbow, try_to_use_simd, ssaa, dont_show_holes);
// we'll draw the contour in myrtle
let myrtle = |_x, _y| Color::new(100, 100, 255, 255);
canvas.fill(&contour, myrtle, try_to_use_simd, ssaa, dont_show_holes);
// Time to use our render!
let pixels: &[Color] = canvas.pixels();
let bytes: &[u8] = pixels.as_bytes();
演示:PNG输出
查看png_demo
示例以生成此图像
依赖项
~1.5MB
~22K SLoC