psiphi75 / sonogram

A spectrograph utility written in Rust
GNU General Public License v3.0
39 stars 12 forks source link

Create specific points for the gradient #8

Open psiphi75 opened 2 years ago

psiphi75 commented 2 years ago

@psiphi75 I was wondering if the gradient could be done the other way around, mapping dB threshold values to colours?

So something like..

let mut gradient = ColourGradient::new();
gradient.add_colour(RGBAColour::new(-100.0, 0, 0, 0, 255));     // Black - I was originally thinking -f32::INFINITY but it might be better to define a lower bound
gradient.add_colour(RGBAColour::new(-60.0, 55, 0, 110, 255));  // Purple
gradient.add_colour(RGBAColour::new(-40.0, 0, 0, 180, 255));   // Blue
gradient.add_colour(RGBAColour::new(-20.0, 0, 255, 255, 255)); // Cyan
gradient.add_colour(RGBAColour::new(-10.0, 255, 255, 0, 255)); // Green
gradient.add_colour(RGBAColour::new(-0.0, 255, 0, 0, 255));   // Red

This way you could define a minimum and maximum amplitude range, and generating the gradient would be much easier outside the package as the same colour stops can be calculated based on that range. What do you think?

Originally posted by @juho in https://github.com/psiphi75/sonogram/issues/6#issuecomment-1013797284