【问题标题】:Core Plot: Random Colors for Scatter Plot(s)核心图:散点图的随机颜色
【发布时间】:2014-05-08 00:32:39
【问题描述】:

我正在设计一个图表,上面有多个散点图。每个数据集的散点图数量都会发生变化。我正在尝试按颜色区分散点图,但是遇到了一些麻烦。

目前,我有一个 for 循环,它为数组中的每个对象创建一个散点图。在 for 循环中,我根据随机数设置颜色:

lineStyle.lineColor = [CPTColor colorWithComponentRed:((arc4random()%255)/255.0) 绿色:((arc4random()%255)/255.0) 蓝色:((arc4random()%255)/255.0) 阿尔法: 1.0];

这有时会起作用,但有时颜色可能很难与其他颜色区分开来,或者可能是全白的。有没有更好的方法来生成随机颜色(可能类似于饼图生成颜色的方式)?

【问题讨论】:

    标签: core-plot


    【解决方案1】:

    我认为这个问题中没有任何具体的核心情节,这实际上只是以编程方式生成配色方案的问题。

    作为一个关于如何比纯随机数做得更好的想法,这里有一些几乎是伪代码,我将如何做到这一点:

    float red = 0;
    float blue = 0;
    float green = 0;
    while(need more colors){
        float colorToInc = (arc4Random()%100)/100;
        float incValue = (arc4Random()%100)/500;//value between 0 and .2
        if(colorToInc < .3){
            red += incValue;
            if(red > 1)
                red -= 1;
        }else if(colorToInc < .7){
            green += incValue;
            if(green > 1)
                green -= 1;
        }else{
            blue += incValue;
            if(blue > 1)
                blue -= 1;
        }
        newcolor = [color with red:red blue:blue green:green];
    }
    

    【讨论】:

      【解决方案2】:

      以下对我有用:

      red = (arc4random()%100)/100.0;
      green = (arc4random()%100)/100.0;
      blue = (arc4random()%100)/100.0;
      [UIColor colorWithRed:red green:green blue:blue alpha:1];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多