Skip to content

Commit adfc5a8

Browse files
committed
update docs
1 parent 7d5bc59 commit adfc5a8

File tree

5 files changed

+55
-19
lines changed

5 files changed

+55
-19
lines changed

PRESET.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ All preset gradients are in the domain [0..1]. Uniform B-splines is used to inte
44

55
![img](docs/images/rgb-plot.png)
66

7+
```rust
8+
use colorgrad::Gradient;
9+
10+
let g = colorgrad::preset::viridis();
11+
12+
assert_eq!(g.domain(), (0.0, 1.0));
13+
14+
println!("{}", g.at(0.27).to_hex_string());
15+
16+
for color in g.colors_iter(35) {
17+
println!("{:?}", color.to_rgba8());
18+
}
19+
```
20+
721
## Diverging
822

923
`colorgrad::preset::br_bg()`

src/gradient/basis.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ fn basis(t1: f32, v0: f32, v1: f32, v2: f32, v3: f32) -> f32 {
2020
feature = "named-colors",
2121
doc = r##"
2222
```
23-
# use std::error::Error;
23+
# fn main() -> Result<(), Box<dyn std::error::Error>> {
24+
# use colorgrad::{GradientBuilder, BasisGradient};
2425
use colorgrad::Gradient;
2526
26-
# fn main() -> Result<(), Box<dyn Error>> {
27-
let grad = colorgrad::GradientBuilder::new()
27+
let grad = GradientBuilder::new()
2828
.html_colors(&["deeppink", "gold", "seagreen"])
29-
.build::<colorgrad::BasisGradient>()?;
29+
.build::<BasisGradient>()?;
3030
# Ok(())
3131
# }
32-
```"##
32+
```
33+
"##
3334
)]
3435
#[derive(Debug, Clone)]
3536
pub struct BasisGradient {

src/gradient/catmull_rom.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ use crate::{convert_colors, BlendMode, Color, Gradient, GradientBuilder, Gradien
99
feature = "named-colors",
1010
doc = r##"
1111
```
12-
# use std::error::Error;
12+
# fn main() -> Result<(), Box<dyn std::error::Error>> {
13+
# use colorgrad::{GradientBuilder, CatmullRomGradient};
1314
use colorgrad::Gradient;
1415
15-
# fn main() -> Result<(), Box<dyn Error>> {
16-
let grad = colorgrad::GradientBuilder::new()
16+
let grad = GradientBuilder::new()
1717
.html_colors(&["deeppink", "gold", "seagreen"])
18-
.build::<colorgrad::CatmullRomGradient>()?;
18+
.build::<CatmullRomGradient>()?;
1919
# Ok(())
2020
# }
21-
```"##
21+
```
22+
"##
2223
)]
2324
#[derive(Debug, Clone)]
2425
pub struct CatmullRomGradient {

src/gradient/inverse.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
use crate::{Color, Gradient};
22

3-
/// A gradient that inverts the gradient of another gradient.
4-
///
5-
/// The minimum value of the inner gradient will be the maximum value of the inverse gradient and
6-
/// vice versa.
3+
#[cfg_attr(
4+
feature = "preset",
5+
doc = r##"
6+
A special gradient that inverts the inner gradient.
7+
8+
The minimum value of the inner gradient will be the maximum value of the inverse gradient and
9+
vice versa.
10+
11+
```
12+
use colorgrad::Gradient;
13+
14+
let gradient = colorgrad::preset::magma();
15+
let inverted = gradient.inverse();
16+
17+
assert_eq!(gradient.at(0.9).to_rgba8(), inverted.at(0.1).to_rgba8());
18+
19+
for color in inverted.colors_iter(15) {
20+
println!("{}", color.to_hex_string());
21+
}
22+
```
23+
"##
24+
)]
725
#[derive(Clone)]
826
pub struct InverseGradient<'a> {
927
inner: Box<dyn Gradient + 'a>,

src/gradient/linear.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ use crate::{BlendMode, Color, Gradient, GradientBuilder, GradientBuilderError};
77
feature = "named-colors",
88
doc = r##"
99
```
10-
# use std::error::Error;
10+
# fn main() -> Result<(), Box<dyn std::error::Error>> {
11+
# use colorgrad::{BlendMode, GradientBuilder, LinearGradient};
1112
use colorgrad::Gradient;
1213
13-
# fn main() -> Result<(), Box<dyn Error>> {
14-
let grad = colorgrad::GradientBuilder::new()
14+
let grad = GradientBuilder::new()
1515
.html_colors(&["deeppink", "gold", "seagreen"])
16-
.build::<colorgrad::LinearGradient>()?;
16+
.mode(BlendMode::Oklab)
17+
.build::<LinearGradient>()?;
1718
# Ok(())
1819
# }
19-
```"##
20+
```
21+
"##
2022
)]
2123
#[derive(Debug, Clone)]
2224
pub struct LinearGradient {

0 commit comments

Comments
 (0)