【问题标题】:How to generate n colors between two colors android如何在两种颜色之间生成n种颜色android
【发布时间】:2020-01-30 10:06:35
【问题描述】:

我点击了这个参考链接:android color between two colors, based on percentage?

但是这里有可能在不通过任何百分比的情况下获得 n 种颜色。

我尝试了两种方法:

起始颜色:(a,b,c) 结束颜色:(d,e,f) 计数为 24

  1. 我用了这个公式

(a+(d-a)/24, b+(e-b)/24, c+(f-c)/24), (a+2*(d-a)/24, b+2*(e-b)/24, c+2 *(f-c)/24) 和 (a+3*(d-a)/24, b+3*(e-b)/24, c+3*(f-c)/24) 等...

但没用

我的期望值:

0 : 96,76,252
    - 1 : 75,93,255         
    - 2 : 56,111,255              
    - 3 : 37,129,252
    - 4 : 21,146,241
    - 5 : 8,163,226
    - 6 : 0,179,208
    - 7 : 0,192,186
    - 8 : 0,204,163
    - 9 : 1,213,140
    - 10 : 12,220,117
    - 11 : 26,224,95
    - 12 : 45,225,76  
    - 13 : 68,224,61
    - 14 : 92,221,50
    - 15 : 119,216,43
    - 16 : 146,210,41
    - 17 : 173,204,45
    - 18 : 198,197,53
    - 19 : 222,190,66
    - 20 : 242,184,82                                          
    - 21 : 255,179,102
    - 22 : 255,176,123
    - 23 : 255,174,146

【问题讨论】:

  • 如果你想要 (a,b,c) 和 (d,e,f) 之间的 3 种颜色,你想要 (a+(d-a)/4, b+(e-b)/4, c+(f-c) )/4), (a+2*(d-a)/4, b+2*(e-b)/4, c+2*(f-c)/4) 和 (a+3*(d-a)/4, b+ 3*(e-b)/4, c+3*(f-c)/4)
  • 颜色插值好像已经问过了:stackoverflow.com/questions/17544157/…
  • 这里是4,是我想要的n种颜色
  • 4 是 n+1,其中 n 是您要生成的颜色数
  • 但它没有给出确切的值,我想要这样:0:96,76,252 1:75,93,255 2:56,111,255 3:37,129,252 4:21,146,241 - 5:8,163,226 - 6:0,179, 7:0,192,186 - 8:0,204,163 - 9:1,213,140 - 10:12,220,117 - 11:26,224,95 - 12:45,225,76 - 13:68,224,61 - 14:92,224,50 - 15:119,221,50 - 15:119,216,43 - 16:146,210, 41 - 17 : 173,204,45 - 18 : 198,197,53 - 19 : 222,190,66 - 20 : 242,184,82 - 21 : 255,179,102 - 22 : 255,176,123 - 23 : 255,174,146s>s

标签: android color-scheme


【解决方案1】:

您可以通过这个从颜色列表中获取随机颜色。

类 RandomColorsPicker { 私有堆栈更改颜色、颜色;

    public RandomColorsPicker() {
        colors = new Stack<>();
        changeColors =new Stack<>();
        changeColors.addAll(Arrays.asList(
                0xfff44336,0xffe91e63,0xff9c27b0,0xff673ab7,
                0xff3f51b5,0xff2196f3,0xff03a9f4,0xff00bcd4,
                0xff009688,0xff4caf50,0xff8bc34a,0xffcddc39
                )
        );
    }

    public int getColors() {
        if (colors.size()==0) {
            while(!changeColors.isEmpty())
                colors.push(changeColors.pop());
            Collections.shuffle(colors);
        }
        Integer color= colors.pop();
        changeColors.push(color);
        return color;
    }
}

并通过使用它来获取颜色

          RandomColorsPicker colors=new RandomColorsPicker();
            int color=colors.getColors();
            String hex = Integer.toHexString(color);

【讨论】:

  • 不是随机颜色,我需要在开始颜色和结束颜色等两种颜色之间生成,然后我需要在 n 种颜色之间生成
  • 所以你需要通过百分比来获取像这样的颜色 new ArgbEvaluator().evaluate(0.75, 0x00ff00, 0xff0000);
  • 我需要调用 new ArgbEvaluator().evaluate(0.75, 0x00ff00, 0xff0000) 的地方。起始颜色:96,76,252 结束颜色:255,174,146 这些是我的颜色
  • 当你想改变颜色时,只需传递一个浮点数以获得不同的颜色
  • 这里我想要起始颜色和结束颜色之间的 12 种颜色,通过使用该逻辑我怎样才能得到
猜你喜欢
  • 2013-07-06
  • 2018-10-21
  • 2016-08-07
  • 1970-01-01
  • 2012-11-27
  • 2013-08-02
  • 2019-12-07
  • 2011-05-23
  • 1970-01-01
相关资源
最近更新 更多