Git Product home page Git Product logo

Comments (2)

mazznoer avatar mazznoer commented on June 19, 2024

You can use this function to do that.

// map t from range [a, b] to range [0, 1]
fn norm(t: f64, a: f64, b: f64) -> f64
{
    (t-a) * (1.0 / (b-a))
}

let grad = colorgrad::rainbow();

// domain is from -100 to 100.
grad.at(norm(0.0, -100.0, 100.0));

// domain is from 0 to 50.
grad.at(norm(0.0, 0.0, 50.0));

from colorgrad-rs.

HHogg avatar HHogg commented on June 19, 2024

Thanks for the response @mazznoer.

As there is a domain that is used internally, I wonder if you'd be open to an API to allow it to be configured. It would be helpful from an API perspective, where you have a gradient stored and used in lots of place. The current options as you say is to either interpolate the values on each call, or create a proxy to it.

from colorgrad-rs.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.