Configure Domain and Color Positions
masterThe default domain for a gradient is [0.0, 1.0]. You can use the .domain() method to change the range or to assign specific positions to the colors provided in the builder.
- To set a range like
[0.0, 100.0], pass&[0.0, 100.0]to.domain(). - To assign specific colors to specific points in the domain, pass a slice containing those points, e.g.,
&[0.0, 0.7, 1.0].
// Set domain to [0..100]
let g = colorgrad::GradientBuilder::new()
.html_colors(&["deeppink", "gold", "seagreen"])
.domain(&[0.0, 100.0])
.build::<colorgrad::LinearGradient>()?;
// Set exact positions for colors within the default [0..1] domain
let g = colorgrad::GradientBuilder::new()
.html_colors(&["deeppink", "gold", "seagreen"])
.domain(&[0.0, 0.7, 1.0])
.build::<colorgrad::LinearGradient>()?;