项目作者: carrotflakes

项目描述 :
pure Rust 2D graphics library
高级语言: Rust
项目地址: git://github.com/carrotflakes/nanachi.git
创建时间: 2020-02-11T13:49:53Z
项目社区:https://github.com/carrotflakes/nanachi

开源协议:

下载


Nanachi - pure Rust 2D graphics library

Build Status
Crates.io
Documentation

This is my hobby project. If you are looking for a 2D graphics library in Rust, tiny-skia is a good alternate.

nanachi

Generated by cargo run --release --example nanachi

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:

  1. use image::RgbaImage;
  2. use nanachi::{
  3. compositor,
  4. context::{Context, FillStyle},
  5. fill_color, fill_rule,
  6. path_builder::PathBuilder,
  7. pixel::Rgba,
  8. };
  9. let (width, height) = (512, 512);
  10. // Make a Context
  11. let mut context = Context::from_pixel(width, height, Rgba([1.0, 1.0, 1.0, 1.0])).high_quality();
  12. // Make a Path
  13. let mut builder = PathBuilder::new();
  14. builder.move_to(100.0, 100.0);
  15. builder.line_to(200.0, 100.0);
  16. builder.line_to(200.0, 200.0);
  17. builder.line_to(100.0, 200.0);
  18. builder.close();
  19. let path = builder.end();
  20. // Make a FillStyle for filling
  21. let fill_style = FillStyle::new(
  22. fill_color::Solid::new(Rgba([1.0, 0.0, 0.0, 0.7])),
  23. compositor::SrcOver,
  24. fill_rule::NonZero,
  25. );
  26. // Fill the path
  27. context.fill(&path, &fill_style);
  28. // Make a FillStyle for stroking
  29. let fill_style = FillStyle::new(
  30. fill_color::Solid::new(Rgba([0.0, 0.0, 1.0, 1.0])),
  31. compositor::SrcOver,
  32. fill_rule::NonZero,
  33. );
  34. // Stroke the path
  35. context.stroke(&path, &fill_style, 8.0);
  36. // Save the image
  37. let img: RgbaImage = (&context.image).into();
  38. img.save("./basic.png").unwrap();

Author

Copyright (c) 2020 carrotflakes (carrotflakes@gmail.com)

License

Licensed under either of

at your option.