Exemplo n.º 1
0
 public PaletteColor(PaletteColor pc)
 {
     this.Location   = pc.Location;
     this.Component1 = pc.Component1;
     this.Component2 = pc.Component2;
     this.Component3 = pc.Component3;
 }
Exemplo n.º 2
0
        public Palette(string name, List <PaletteColor> clrs, bool hsl)
        {
            this.Name   = name;
            this.colors = new List <PaletteColor>();
            this.HSL    = hsl;

            PaletteColor defaultStartColor, defaultEndColor;

            if (this.HSL)
            {
                defaultStartColor = new PaletteColor(0m, 0, 1, 0.5m);
                defaultEndColor   = new PaletteColor(1m, 360, 1, 0.5m);
            }
            else
            {
                defaultStartColor = new PaletteColor(0m, 0xFF, 0xFF, 0xFF);
                defaultEndColor   = new PaletteColor(1m, 0, 0, 0);
            }

            if (clrs.Count == 0)
            {
                this.colors.Add(defaultStartColor);
                this.colors.Add(defaultEndColor);
            }
            else if (clrs.Count == 1)
            {
                this.colors.Add(clrs[0]);
                this.colors[0].Location = 0;

                this.colors.Add(defaultEndColor);
            }
            else
            {
                decimal prevLoc = -0.05m;
                foreach (PaletteColor pc in clrs)
                {
                    if (!(pc.Location - prevLoc < 0.05m || pc.Location > 1m))
                    {
                        if ((hsl && checkIfValidHSL(pc.Component1, pc.Component2, pc.Component3)) ||
                            (!hsl && checkIfValidRGB((int)pc.Component1, (int)pc.Component2, (int)pc.Component3)))
                        {
                            this.colors.Add(pc);
                        }
                    }
                }

                if (this.colors.Count == 0)
                {
                    this.colors.Add(defaultStartColor);
                    this.colors.Add(defaultEndColor);
                }
                else if (this.colors.Count == 1)
                {
                    this.colors.Add(defaultEndColor);
                }

                this.colors[0].Location = 0;
                this.colors[this.colors.Count - 1].Location = 1;
            }
        }
Exemplo n.º 3
0
        public Color getColor(decimal locInPalette)
        {
            if (locInPalette > 1)
            {
                return(Color.White);
            }

            int i;

            for (i = 0; i < colors.Count; i++)
            {
                if (colors[i].Location > locInPalette)
                {
                    break;
                }
            }
            if (i == colors.Count)
            {
                i--;
            }

            int          startingColor           = i - 1;
            int          endingColor             = i;
            PaletteColor sColor                  = colors[startingColor];
            PaletteColor eColor                  = colors[endingColor];
            decimal      percentLocBetweenColors = ((locInPalette - sColor.Location) / (eColor.Location - sColor.Location));

            percentLocBetweenColors = (percentLocBetweenColors > 1) ? 1 : percentLocBetweenColors;

            decimal c1diff = eColor.Component1 - sColor.Component1;
            decimal c2diff = eColor.Component2 - sColor.Component2;
            decimal c3diff = eColor.Component3 - sColor.Component3;

            decimal newComponent1 = c1diff * percentLocBetweenColors + sColor.Component1;
            decimal newComponent2 = c2diff * percentLocBetweenColors + sColor.Component2;
            decimal newComponent3 = c3diff * percentLocBetweenColors + sColor.Component3;

            if (this.HSL)
            {
                return(HSLtoRGBConversion(newComponent1, newComponent2, newComponent3));
            }
            else
            {
                return(Color.FromArgb((int)newComponent1, (int)newComponent2, (int)newComponent3));
            }
        }
Exemplo n.º 4
0
 public void Insert(int index, PaletteColor pc)
 {
     colors.Insert(index, pc);
 }