Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Common/3.3/ColorGradient.cs @ 17425

Last change on this file since 17425 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 2.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using System.Collections.ObjectModel;
24using System.Drawing;
25
26namespace HeuristicLab.Common {
27  public static class ColorGradient {
28    private const int shades = 256;
29
30    private static List<Color> colors = new List<Color>();
31    private static ReadOnlyCollection<Color> readOnlyColors;
32    public static IList<Color> Colors {
33      get {
34        if (readOnlyColors == null) readOnlyColors = colors.AsReadOnly();
35        return readOnlyColors;
36      }
37    }
38
39    private static List<Color> grayscaledColors = new List<Color>();
40    private static ReadOnlyCollection<Color> readOnlyGrayScaledColors;
41    public static IList<Color> GrayscaledColors {
42      get {
43        if (readOnlyGrayScaledColors == null) readOnlyGrayScaledColors = grayscaledColors.AsReadOnly();
44        return readOnlyGrayScaledColors;
45      }
46    }
47
48    static ColorGradient() {
49      int stepWidth = (256 * 4) / shades;
50      int currentValue;
51      int currentClass;
52      for (int i = 0; i < shades; i++) {
53        currentValue = (i * stepWidth) % 256;
54        currentClass = (i * stepWidth) / 256;
55        switch (currentClass) {
56          case 0: { colors.Add(Color.FromArgb(0, currentValue, 255)); break; }        // blue -> cyan
57          case 1: { colors.Add(Color.FromArgb(0, 255, 255 - currentValue)); break; }  // cyan -> green
58          case 2: { colors.Add(Color.FromArgb(currentValue, 255, 0)); break; }        // green -> yellow
59          case 3: { colors.Add(Color.FromArgb(255, 255 - currentValue, 0)); break; }  // yellow -> red
60        }
61      }
62      for (int i = 0; i < 256; i++)
63        grayscaledColors.Add(Color.FromArgb(255 - i, 255 - i, 255 - i));  // white -> black
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.