how to generate heat maps given the points

前端 未结 8 1780
猫巷女王i
猫巷女王i 2021-02-06 07:59

I want to generate a heat map in windows form. I have a set of points as the input. How to go about doing this in the simplest way? Thanks.

8条回答
  •  自闭症患者
    2021-02-06 08:37

    A solution going from red to yellow to green

    static Color CreateHeatColor(int value, decimal max)
        {
            if (max == 0) max = 1M;
            decimal pct = value/max;
             Color color = new Color();
    
            color.A = 255;
    
            if (pct < 0.34M)
            {
                color.R = (byte) (128 + (127 * Math.Min(3 * pct, 1M)));
                color.G = 0;
                color.B = 0;
            }
            else if (pct < 0.67M)
            {
                color.R = 255;
                color.G = (byte) (255 * Math.Min(3 * (pct - 0.333333M), 1M));
                color.B = 0;
            }
            else
            {
                color.R = (byte)(255 * Math.Min(3 * (1M - pct), 1M));
                color.G = 255;
                color.B = 0;
            }
    
            return color;
        }
    

提交回复
热议问题