use super::super::{ColorExpr, ScalarExpr, VisualError};
use super::VisualProgramBuilder;
use crate::ScalarRamp;
impl VisualProgramBuilder {
pub fn ramp(&mut self, value: ScalarExpr, ramp: ScalarRamp) -> Result<ColorExpr, VisualError> {
let values = ramp.values();
let colors = ramp.colors();
let mut previous_stop = self.scalar(values[0])?;
let mut blended = self.color(colors[0].to_f32())?;
for (stop, color) in values.iter().zip(colors).skip(1) {
let next_stop = self.scalar(*stop)?;
let weight = self.smoothstep(previous_stop, next_stop, value)?;
let next_color = self.color(color.to_f32())?;
blended = self.mix_color(blended, next_color, weight)?;
previous_stop = next_stop;
}
Ok(blended)
}
}