Expand description
§Nanachi
Nanachi is a 2D graphics library for Rust.
§Features
- path filling and stroking
- color with: linear gradients, radial gradients and patterns
- 24 composition types
- anti-aliasing (can be disabled)
- path transformation: translation, scaling and rotation
§Example
Basic usage example is following:
use image::RgbaImage;
use nanachi::{
compositor,
context::{Context, FillStyle},
fill_color, fill_rule,
path_builder::PathBuilder,
pixel::Rgba,
};
let (width, height) = (512, 512);
// Make a Context
let mut context = Context::from_pixel(width, height, Rgba([1.0, 1.0, 1.0, 1.0])).high_quality();
// Make a Path
let mut builder = PathBuilder::new();
builder.move_to(100.0, 100.0);
builder.line_to(200.0, 100.0);
builder.line_to(200.0, 200.0);
builder.line_to(100.0, 200.0);
builder.close();
let path = builder.end();
// Make a FillStyle for filling
let fill_style = FillStyle::new(
fill_color::Solid::new(Rgba([1.0, 0.0, 0.0, 0.7])),
compositor::SrcOver,
fill_rule::NonZero,
);
// Fill the path
context.fill(&path, &fill_style);
// Make a FillStyle for stroking
let fill_style = FillStyle::new(
fill_color::Solid::new(Rgba([0.0, 0.0, 1.0, 1.0])),
compositor::SrcOver,
fill_rule::NonZero,
);
// Stroke the path
context.stroke(&path, &fill_style, 8.0);
// Save the image
let img: RgbaImage = (&context.image).into();
img.save("./basic.png").unwrap();
Re-exports§
pub extern crate image;
Modules§
- buffer
Buffer
trait represents an image.- compositor
- Collection of composition types.
- context
Context
provides high level API.- draw_
image - fill_
color - Collection of colorization types.
- fill_
rule FillRule
controls the area of path filling.- image_
crate_ adapter - Interfaces for image crate.
- interpolation
- Collection of interpolation types.
- k_curve
- Κ-curves implementation
- matrix
- Affine transformation
- path
Path
for filling and stroking.- path_
builder - PathBuilder
- path_
data_ notation - path_
flatten - Make path flatten.
- path_
outline - Generate path outline.
- path_
segments - Segments
- path_
transform - Path transformation.
- pixel
Pixel
trait represents a pixel.- point
Point
represents x, y coordinates.- primitives
- Primitive shape generators.
- rasterize
rastarize
method draws a path- writer