Skip to content

Commit

Permalink
fix deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mazznoer committed Jul 22, 2022
1 parent 4ffea47 commit 96cf214
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
Add this to your `Cargo.toml`

```toml
colorgrad = "0.6.0"
colorgrad = "0.6.1"
```

## Custom Gradient
Expand All @@ -48,11 +48,11 @@ use colorgrad::Color;

let g = colorgrad::CustomGradient::new()
.colors(&[
Color::from_rgb_u8(0, 206, 209),
Color::from_rgb_u8(255, 105, 180),
Color::from_rgb(0.274, 0.5, 0.7),
Color::from_hsv(50.0, 1.0, 1.0),
Color::from_hsv(348.0, 0.9, 0.8),
Color::from_rgba8(0, 206, 209, 255),
Color::from_rgba8(255, 105, 180, 255),
Color::new(0.274, 0.5, 0.7, 1.0),
Color::from_hsva(50.0, 1.0, 1.0, 1.0),
Color::from_hsva(348.0, 0.9, 0.8, 1.0),
])
.build()?;
```
Expand Down Expand Up @@ -303,8 +303,8 @@ use std::io::BufReader;

let input = File::open("examples/Abstract_1.ggr")?;
let buf = BufReader::new(input);
let fg = Color::from_rgb(0.0, 0.0, 0.0);
let bg = Color::from_rgb(1.0, 1.0, 1.0);
let fg = Color::new(0.0, 0.0, 0.0, 1.0);
let bg = Color::new(1.0, 1.0, 1.0, 1.0);
let (grad, name) = colorgrad::parse_ggr(buf, &fg, &bg)?;

assert_eq!(name, "Abstract 1");
Expand All @@ -327,15 +327,15 @@ assert_eq!(grad.domain(), (0.0, 1.0));
```rust
let grad = colorgrad::blues();

assert_eq!(grad.at(0.0).rgba_u8(), (247, 251, 255, 255));
assert_eq!(grad.at(0.5).rgba_u8(), (109, 174, 213, 255));
assert_eq!(grad.at(1.0).rgba_u8(), (8, 48, 107, 255));
assert_eq!(grad.at(0.0).to_rgba8(), [247, 251, 255, 255]);
assert_eq!(grad.at(0.5).to_rgba8(), [109, 174, 213, 255]);
assert_eq!(grad.at(1.0).to_rgba8(), [8, 48, 107, 255]);

assert_eq!(grad.at(0.3).rgba_u8(), grad.repeat_at(0.3).rgba_u8());
assert_eq!(grad.at(0.3).rgba_u8(), grad.reflect_at(0.3).rgba_u8());
assert_eq!(grad.at(0.3).to_rgba8(), grad.repeat_at(0.3).to_rgba8());
assert_eq!(grad.at(0.3).to_rgba8(), grad.reflect_at(0.3).to_rgba8());

assert_eq!(grad.at(0.7).rgba_u8(), grad.repeat_at(0.7).rgba_u8());
assert_eq!(grad.at(0.7).rgba_u8(), grad.reflect_at(0.7).rgba_u8());
assert_eq!(grad.at(0.7).to_rgba8(), grad.repeat_at(0.7).to_rgba8());
assert_eq!(grad.at(0.7).to_rgba8(), grad.reflect_at(0.7).to_rgba8());
```

The difference of `at()`, `repeat_at()` and `reflect_at()`.
Expand Down Expand Up @@ -396,8 +396,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut imgbuf = image::ImageBuffer::new(width, height);

for (x, _, pixel) in imgbuf.enumerate_pixels_mut() {
let (r, g, b, a) = grad.at(x as f64 / width as f64).rgba_u8();
*pixel = image::Rgba([r, g, b, a]);
let rgba = grad.at(x as f64 / width as f64).to_rgba8();
*pixel = image::Rgba(rgba);
}

imgbuf.save("gradient.png")?;
Expand All @@ -423,8 +423,8 @@ fn main() {

for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
let t = ns.get([x as f64 * scale, y as f64 * scale]);
let (r, g, b, a) = grad.at(remap(t, -0.5, 0.5, 0.0, 1.0)).rgba_u8();
*pixel = image::Rgba([r, g, b, a]);
let rgba = grad.at(remap(t, -0.5, 0.5, 0.0, 1.0)).to_rgba8();
*pixel = image::Rgba(rgba);
}

imgbuf.save("noise.png").unwrap();
Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! let g = colorgrad::rainbow();
//!
//! assert_eq!(g.domain(), (0.0, 1.0)); // all preset gradients are in the domain [0..1]
//! assert_eq!(g.at(0.5).rgba_u8(), (175, 240, 91, 255));
//! assert_eq!(g.at(0.5).to_rgba8(), [175, 240, 91, 255]);
//! assert_eq!(g.at(0.5).to_hex_string(), "#aff05b");
//! ```
//!
Expand All @@ -20,12 +20,12 @@
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let g = colorgrad::CustomGradient::new()
//! .colors(&[
//! Color::from_rgb_u8(255, 0, 0),
//! Color::from_rgb_u8(0, 255, 0),
//! Color::from_rgba8(255, 0, 0, 255),
//! Color::from_rgba8(0, 255, 0, 255),
//! ])
//! .build()?;
//!
//! assert_eq!(g.at(0.0).rgba_u8(), (255, 0, 0, 255));
//! assert_eq!(g.at(0.0).to_rgba8(), [255, 0, 0, 255]);
//! assert_eq!(g.at(0.0).to_hex_string(), "#ff0000");
//! assert_eq!(g.at(1.0).to_hex_string(), "#00ff00");
//! # Ok(())
Expand All @@ -48,8 +48,8 @@
//! let mut imgbuf = image::ImageBuffer::new(width, height);
//!
//! for (x, _, pixel) in imgbuf.enumerate_pixels_mut() {
//! let (r, g, b, a) = grad.at(x as f64 / width as f64).rgba_u8();
//! *pixel = image::Rgba([r, g, b, a]);
//! let rgba = grad.at(x as f64 / width as f64).to_rgba8();
//! *pixel = image::Rgba(rgba);
//! }
//!
//! imgbuf.save("gradient.png")?;
Expand All @@ -75,8 +75,8 @@
//!
//! for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
//! let t = ns.get([x as f64 * scale, y as f64 * scale]);
//! let (r, g, b, a) = grad.at(remap(t, -0.5, 0.5, 0.0, 1.0)).rgba_u8();
//! *pixel = image::Rgba([r, g, b, a]);
//! let rgba = grad.at(remap(t, -0.5, 0.5, 0.0, 1.0)).to_rgba8();
//! *pixel = image::Rgba(rgba);
//! }
//!
//! imgbuf.save("noise.png").unwrap();
Expand Down

0 comments on commit 96cf214

Please sign in to comment.