• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript color.color2rgba函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中core/util/color.color2rgba函数的典型用法代码示例。如果您正苦于以下问题:TypeScript color2rgba函数的具体用法?TypeScript color2rgba怎么用?TypeScript color2rgba使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了color2rgba函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: it

 it("should turn 3-element hex colors to tuples", () => {
   expect(color2rgba('#000')).to.eql([0, 0, 0, 1])
   expect(color2rgba('#f00')).to.eql([1, 0, 0, 1])
   expect(color2rgba('#0f0')).to.eql([0, 1, 0, 1])
   expect(color2rgba('#00f')).to.eql([0, 0, 1, 1])
   expect(color2rgba('#fff')).to.eql([1, 1, 1, 1])
 })
开发者ID:jsignell,项目名称:bokeh,代码行数:7,代码来源:color.ts


示例2: function

export const attach_color = function(prog, vbo, att_name, n, visual, prefix) {
    // Attach the color attribute to the program. If there's just one color,
    // then use this single color for all vertices (no VBO). Otherwise we
    // create an array and upload that to the VBO, which we attahce to the prog.
    let rgba;
    const m = 4;
    const colorname = prefix + '_color';
    const alphaname = prefix + '_alpha';

    if (!visual.doit) {
      // Don't draw (draw transparent)
      vbo.used = false;
      return prog.set_attribute(att_name, 'vec4', [0,0,0,0]);
    } else if (visual_prop_is_singular(visual, colorname) && visual_prop_is_singular(visual, alphaname)) {
      // Nice and simple; both color and alpha are singular
      vbo.used = false;
      rgba = color2rgba(visual[colorname].value(), visual[alphaname].value());
      return prog.set_attribute(att_name, 'vec4', rgba);
    } else {
      // Use vbo; we need an array for both the color and the alpha
      let alphas, colors;
      vbo.used = true;
      // Get array of colors
      if (visual_prop_is_singular(visual, colorname)) {
        colors = ((() => {
          const result = [];
          for (let i = 0, end = n; i < end; i++) {
            result.push(visual[colorname].value());
          }
          return result;
        })());
      } else {
        colors = visual.cache[colorname+'_array'];
      }
      // Get array of alphas
      if (visual_prop_is_singular(visual, alphaname)) {
        alphas = fill_array_with_float(n, visual[alphaname].value());
      } else {
        alphas = visual.cache[alphaname+'_array'];
      }
      // Create array of rgbs
      const a = new Float32Array(n*m);
      for (let i = 0, end = n; i < end; i++) {
        rgba = color2rgba(colors[i], alphas[i]);
        for (let j = 0, endj = m; j < endj; j++) {
          a[(i*m)+j] = rgba[j];
        }
      }
      // Attach vbo
      vbo.set_size(n*m*4);
      vbo.set_data(0, a);
      return prog.set_attribute(att_name, 'vec4', vbo);
    }
  };
开发者ID:FourtekIT-incubator,项目名称:bokeh,代码行数:54,代码来源:base.ts


示例3: _set_visuals

    _set_visuals() {

      const color = color2rgba(this.glyph.visuals.line.line_color.value(), this.glyph.visuals.line.line_alpha.value());
      const cap = this.CAPS[this.glyph.visuals.line.line_cap.value()];
      const join = this.JOINS[this.glyph.visuals.line.line_join.value()];

      this.prog.set_uniform('u_color', 'vec4', color);
      this.prog.set_uniform('u_linewidth', 'float', [this.glyph.visuals.line.line_width.value()]);
      this.prog.set_uniform('u_antialias', 'float', [0.9]);  // Smaller aa-region to obtain crisper images

      this.prog.set_uniform('u_linecaps', 'vec2', [cap, cap]);
      this.prog.set_uniform('u_linejoin', 'float', [join]);
      this.prog.set_uniform('u_miter_limit', 'float', [10.0]);  // 10 should be a good value
      // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-miterlimit

      const dash_pattern = this.glyph.visuals.line.line_dash.value();
      let dash_index = 0; let dash_period = 1;
      if (dash_pattern.length) {
        [dash_index, dash_period] = this.dash_atlas.get_atlas_data(dash_pattern);
      }
      this.prog.set_uniform('u_dash_index', 'float', [dash_index]);  // 0 means solid line
      this.prog.set_uniform('u_dash_phase', 'float', [this.glyph.visuals.line.line_dash_offset.value()]);
      this.prog.set_uniform('u_dash_period', 'float', [dash_period]);
      this.prog.set_uniform('u_dash_caps', 'vec2', [cap, cap]);
      return this.prog.set_uniform('u_closed', 'float', [0]);  // We dont do closed lines
    }
开发者ID:FourtekIT-incubator,项目名称:bokeh,代码行数:26,代码来源:line.ts


示例4: describe

describe("color module", () => {

  const halfgray = color2rgba('rgb(128, 128, 128)')

  it("should turn 6-element hex colors to tuples", () => {
    expect(color2rgba('#000000')).to.eql([0, 0, 0, 1])
    expect(color2rgba('#ff0000')).to.eql([1, 0, 0, 1])
    expect(color2rgba('#00ff00')).to.eql([0, 1, 0, 1])
    expect(color2rgba('#0000ff')).to.eql([0, 0, 1, 1])
    expect(color2rgba('#ffffff')).to.eql([1, 1, 1, 1])
    expect(color2rgba('#808080')).to.eql(halfgray)
  })

  it("should turn 3-element hex colors to tuples", () => {
    expect(color2rgba('#000')).to.eql([0, 0, 0, 1])
    expect(color2rgba('#f00')).to.eql([1, 0, 0, 1])
    expect(color2rgba('#0f0')).to.eql([0, 1, 0, 1])
    expect(color2rgba('#00f')).to.eql([0, 0, 1, 1])
    expect(color2rgba('#fff')).to.eql([1, 1, 1, 1])
  })

  it("should turn known css color names to tuples", () => {
    expect(color2rgba('red')).to.eql([1, 0, 0, 1])
    expect(color2rgba('yellow')).to.eql([1, 1, 0, 1])
    expect(color2rgba('gray')).to.eql(halfgray)
  })

  it("should turn known rgb() colors to tuples", () => {
    expect(color2rgba('rgb(0, 0, 0)')).to.eql([0, 0, 0, 1])
    expect(color2rgba('rgb(255, 0, 0)')).to.eql([1, 0, 0, 1])
    expect(color2rgba('rgb(0, 255, 0)')).to.eql([0, 1, 0, 1])
    expect(color2rgba('rgb(0, 0, 255)')).to.eql([0, 0, 1, 1])
    expect(color2rgba('rgb(128, 128, 128)')).to.eql(halfgray)
  })

  it("should provide the given alpha value", () => {
    expect(color2rgba('#ff0000', 0.1)).to.eql([1, 0, 0, 0.1])
    expect(color2rgba('#ff0000', 0.5)).to.eql([1, 0, 0, 0.5])
    expect(color2rgba('#0f0', 0.5)).to.eql([0, 1, 0, 0.5])
    expect(color2rgba('blue', 0.5)).to.eql([0, 0, 1, 0.5])
  })

  it("should turn rgb() colors to tuples", () => {
    expect(color2rgba('rgb(0, 0, 0)')).to.eql([0, 0, 0, 1])
    expect(color2rgba('rgb(255, 0, 0)')).to.eql([1, 0, 0, 1])
    expect(color2rgba('rgb(0, 255, 0)')).to.eql([0, 1, 0, 1])
    expect(color2rgba('rgb(0, 0, 255)')).to.eql([0, 0, 1, 1])
    expect(color2rgba('rgb(128, 128, 128)')).to.eql(halfgray)
  })

  it("should turn rgba() colors to tuples, overriding alpha", () => {
    expect(color2rgba('rgba(0, 0, 0, 0)')).to.eql([0, 0, 0, 0])
    expect(color2rgba('rgba(0, 0, 0, 0)', 0.5)).to.eql([0, 0, 0, 0])
    expect(color2rgba('rgba(255, 0, 0, 1)', 0.5)).to.eql([1, 0, 0, 1])
    expect(color2rgba('rgba(255, 0, 0, 0.4)', 0.5)).to.eql([1, 0, 0, 0.4])
  })

  it("should turn NaN or null to transparent color", () => {
    // XXX: any required due to mismatch between function's signature
    //      and its garbage in/garbage out implementation.
    expect(color2rgba(null as any)).to.eql([0, 0, 0, 0])
    expect(color2rgba(''   as any)).to.eql([0, 0, 0, 0])
    expect(color2rgba(NaN  as any)).to.eql([0, 0, 0, 0])
    expect(color2rgba(NaN  as any, 0.5)).to.eql([0, 0, 0, 0])
    expect(color2rgba(NaN  as any, 1.0)).to.eql([0, 0, 0, 0])
  })
})
开发者ID:jsignell,项目名称:bokeh,代码行数:67,代码来源:color.ts



注:本文中的core/util/color.color2rgba函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript data_structures.Matrix类代码示例发布时间:2022-05-24
下一篇:
TypeScript color.color2hex函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap