Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Less.js中计算cubehelix颜色方案?_Less_Cielab - Fatal编程技术网

如何在Less.js中计算cubehelix颜色方案?

如何在Less.js中计算cubehelix颜色方案?,less,cielab,Less,Cielab,我想用更少的时间来计算cubehelix颜色方案,这样我可以调整一些变量。我相信这需要CIE L*a*b颜色系统。我遇到了Chroma.js,它似乎可以用于计算颜色,但现在我想将其集成到Less中。已经在JavaScript中实现并扩展了cubehelix,作为D3.js可视化库的一个工具(请参阅) 你可以用Bostock插件的代码编写一个更便宜的程序 从github下载并解压缩源代码,网址为: 运行npm安装 创建一个名为lib/less/functions/cubehelix.js的文件,并

我想用更少的时间来计算cubehelix颜色方案,这样我可以调整一些变量。我相信这需要CIE L*a*b颜色系统。我遇到了Chroma.js,它似乎可以用于计算颜色,但现在我想将其集成到Less中。

已经在JavaScript中实现并扩展了cubehelix,作为D3.js可视化库的一个工具(请参阅)

你可以用Bostock插件的代码编写一个更便宜的程序

  • 从github下载并解压缩源代码,网址为:
  • 运行
    npm安装
  • 创建一个名为
    lib/less/functions/cubehelix.js的文件,并将以下内容写入其中:

    var Color = require("../tree/color"),
    functionRegistry = require("./function-registry");
    
    function d3_interpolate(y) {
    return function(a, b) {
          a = a.toHSL();
          b = b.toHSL();
          var radians = Math.PI / 180;
          var ah = (a.h + 120) * radians,
              bh = (b.h + 120) * radians - ah,
              as = a.s,
              bs = b.s - as,
              al = a.l,
              bl = b.l - al;
    
          if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
          if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah;
    
          return function(t) {
            var h = ah + bh * t,
                l = Math.pow(al + bl * t, y),
                a = (as + bs * t) * l * (1 - l),
                cosh = Math.cos(h),
                sinh = Math.sin(h);
            return "#"
                + hex(l + a * (-0.14861 * cosh + 1.78277 * sinh))
                + hex(l + a * (-0.29227 * cosh - 0.90649 * sinh))
                + hex(l + a * (+1.97294 * cosh));
          };
        };
      }
    
    function hex(v) {
        var s = (v = v <= 0 ? 0 : v >= 1 ? 255 : v * 255 | 0).toString(16);
        return v < 0x10 ? "0" + s : s;
    }
    
    functionRegistry.addMultiple({
    cubehelix: function(y,a,b,t) {
    return new Color(d3_interpolate(y.value)(a,b)(t.value).slice(1),1);
    }   
    });
    
    产出:

    p {
      color: #766cfd;
    }
    p {
      color: #21ba40;
    }
    p {
      color: #4c4c4c;
    }
    
    p {
      color: #766cfd;
    }
    p {
      color: #21ba40;
    }
    p {
      color: #4c4c4c;
    }