MTExample1_8.ColorMap.Hot C# (CSharp) Method

Hot() public method

public Hot ( ) : ].int[
return ].int[
        public int[,] Hot()
        {
            int[,] cmap = new int[colormapLength, 4];
            int n = 3 * colormapLength / 8;
            float[] red = new float[colormapLength];
            float[] green = new float[colormapLength];
            float[] blue = new float[colormapLength];
            for (int i = 0; i < colormapLength; i++) {
                if (i < n)
                    red[i] = 1.0f*(i+1) / n;
                else
                    red[i] = 1.0f;
                if (i < n)
                    green[i] = 0f;
                else if (i >= n && i < 2 * n)
                    green[i] = 1.0f * (i+1 - n) / n;
                else
                    green[i] = 1f;
                if (i < 2 * n)
                    blue[i] = 0f;
                else
                    blue[i] = 1.0f * (i + 1 - 2 * n) / (colormapLength - 2 * n);
                cmap[i, 0] = alphaValue;
                cmap[i, 1] = (int)(255 * red[i]);
                cmap[i, 2] = (int)(255 * green[i]);
                cmap[i, 3] = (int)(255 * blue[i]);
            }
            return cmap;
        }

Usage Example

        private void DrawColorBar(Graphics g, int x, int y, int width, int height,
                                  ColorMap map, string str)
        {
            int[,] cmap = new int[64, 4];
            switch (str)
            {
            case "Jet":
                cmap = map.Jet();
                break;

            case "Hot":
                cmap = map.Hot();
                break;

            case "Gray":
                cmap = map.Gray();
                break;

            case "Cool":
                cmap = map.Cool();
                break;

            case "Summer":
                cmap = map.Summer();
                break;

            case "Autumn":
                cmap = map.Autumn();
                break;

            case "Spring":
                cmap = map.Spring();
                break;

            case "Winter":
                cmap = map.Winter();
                break;
            }

            int ymin = 0;
            int ymax = 32;
            int dy   = height / (ymax - ymin);
            int m    = 64;

            for (int i = 0; i < 32; i++)
            {
                int        colorIndex = (int)((i - ymin) * m / (ymax - ymin));
                SolidBrush aBrush     = new SolidBrush(Color.FromArgb(
                                                           cmap[colorIndex, 0], cmap[colorIndex, 1],
                                                           cmap[colorIndex, 2], cmap[colorIndex, 3]));
                g.FillRectangle(aBrush, x, y + i * dy, width, dy);
            }
        }
All Usage Examples Of MTExample1_8.ColorMap::Hot