GithubHelp home page GithubHelp logo

Turbo color map about colorschemes.jl HOT 6 CLOSED

juliagraphics avatar juliagraphics commented on July 23, 2024 1
Turbo color map

from colorschemes.jl.

Comments (6)

cormullion avatar cormullion commented on July 23, 2024 1

added in 8d98876

from colorschemes.jl.

cormullion avatar cormullion commented on July 23, 2024

Good idea!

I ended up adding the color map colors directly. But I did first try to convert the GLSL code, but I didn't really understand it enough to get the correct results:

function turbocolormap(x)
    kRedVec4   = [-0.05195877, 5.18000081, -30.94853351, 81.96403246]
    kGreenVec4 = [0.16207513, 0.17712472, 15.24091500, -36.50657960]
    kBlueVec4  = [0.55305649, 3.00913185, -5.46192616, -11.11819092]
    kRedVec2   = [-86.53476570, 30.23299484]
    kGreenVec2 = [25.95549545, -5.02738237]
    kBlueVec2  = [27.81927491, -14.87899417]
    x = clamp(x, 0.0, 1.0)
    v4 = [1.0, x, x^2, x^3]    
    v4zw = [v4[3], v4[4]]
    v2 = v4zw * v4[3]
    return [
        dot(v4, kRedVec4)   + dot(v2, kRedVec2),
        dot(v4, kGreenVec4) + dot(v2, kGreenVec2),
        dot(v4, kBlueVec4)  + dot(v2, kBlueVec2)
    ]
end

from colorschemes.jl.

c42f avatar c42f commented on July 23, 2024

Great! I tried translating the GLSL version (https://gist.github.com/mikhailov-work/0d177465a8151eb6ede1768d51d476c7) and I got the same thing. I think it might just somehow have buggy coefficients but perhaps I've forgotten something critical about GLSL.

I made a notebook which computes a better approximation for us:
https://gist.github.com/c42f/f822a7b00258e5c73e27ac4a9db0f418
but I think the sampled version is quite a bit nicer.

from colorschemes.jl.

c42f avatar c42f commented on July 23, 2024

Looks like it's already made its way into d3 as well: https://observablehq.com/@mbostock/turbo

from colorschemes.jl.

cormullion avatar cormullion commented on July 23, 2024

Nice notebook! You got the same result at first as me, it looks a bit burnt or something at the top end... :)

ColorSchemes is a bit basic, it stores everything as arrays of colors. ColorSchemeTools.jl has a few functions for building schemes with functions, but it's all very simplistic and non-scientific...

Peter Kovesi's Perceptual Color Maps is the thing, I think.

from colorschemes.jl.

c42f avatar c42f commented on July 23, 2024

I like that you've got the original sampled colormap in here; I think it's nicer than the polynomial approximation anyway.

I guess this is resolved 👍

from colorschemes.jl.

Related Issues (20)

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.