Exemple #1
0
        /// <summary>
        /// Gets a color from RGB ratios
        /// </summary>
        /// <param name="value1"></param>
        /// <param name="value2"></param>
        /// <param name="value3"></param>
        /// <returns></returns>
        public static Color ColorFromRGBRatios(double value1, double value2, double value3)
        {
            int rValue;
            int gValue;
            int bValue;

            if (value3 == 0)
            {
                rValue = gValue = bValue = (int)(value2 * 255);
            }
            else
            {
                float value4;
                if (value2 <= 0.5)
                {
                    value4 = (float)(value2 + (value2 * value3));
                }
                else
                {
                    value4 = (float)((value2 + value3) - (value2 * value3));
                }
                float value5 = ((float)(2 * value2)) - value4;
                rValue = ColorServices.GetColorChannelValue(value5, value4, (float)(value1 + 120));
                gValue = ColorServices.GetColorChannelValue(value5, value4, (float)value1);
                bValue = ColorServices.GetColorChannelValue(value5, value4, (float)(value1 - 120));
            }
            return(Color.FromArgb(rValue, gValue, bValue));
        }
Exemple #2
0
        private void InitializeHexagons()
        {
            Rectangle clientRectangle = base.ClientRectangle;

            clientRectangle.Inflate(-8, -8);
            clientRectangle.Height -= this.GetHexagonWidth(Math.Min(clientRectangle.Height, clientRectangle.Width)) * 3;
            if (clientRectangle.Height < clientRectangle.Width)
            {
                clientRectangle.Inflate(-(clientRectangle.Width - clientRectangle.Height) / 2, 0);
            }
            else
            {
                clientRectangle.Inflate(0, -(clientRectangle.Height - clientRectangle.Width) / 2);
            }

            //
            int hexagonWidth           = this.GetHexagonWidth(clientRectangle.Height);
            int centerOfMiddleHexagonX = (clientRectangle.Left + clientRectangle.Right) / 2;
            int centerOfMiddleHexagonY = (clientRectangle.Top + clientRectangle.Bottom) / 2;

            //
            this.hexagonElements[0].CurrentColor = Color.White;
            this.hexagonElements[0].SetHexagonPoints((float)centerOfMiddleHexagonX, (float)centerOfMiddleHexagonY, hexagonWidth);
            int index = 1;

            for (int i = 1; i < this.sectorMaximum; i++)
            {
                //
                float currentHexagonY = centerOfMiddleHexagonY;
                float currentHexagonX = centerOfMiddleHexagonX + (hexagonWidth * i);

                for (int innerIndex = 0; innerIndex < (this.sectorMaximum - 1); innerIndex++)
                {
                    int verticalStep   = (int)(hexagonWidth * this.matrix2[innerIndex]);
                    int horizontalStep = (int)(hexagonWidth * this.matrix1[innerIndex]);

                    for (int innermostIndex = 0; innermostIndex < i; innermostIndex++)
                    {
                        double colorQuotient2 = ((0.936 * (this.sectorMaximum - i)) / ((double)this.sectorMaximum)) + 0.12;
                        float  colorQuotient1 = ColorServices.GetColorQuotient(currentHexagonX - centerOfMiddleHexagonX, currentHexagonY - centerOfMiddleHexagonY);
                        this.hexagonElements[index].SetHexagonPoints(currentHexagonX, currentHexagonY, hexagonWidth);
                        this.hexagonElements[index].CurrentColor = ColorServices.ColorFromRGBRatios((double)colorQuotient1, colorQuotient2, 1);
                        currentHexagonY += verticalStep;
                        currentHexagonX += horizontalStep;
                        index++;
                    }
                }
            }

            InitializeGrayscaleHexagons(ref clientRectangle, hexagonWidth, ref centerOfMiddleHexagonX, ref centerOfMiddleHexagonY, ref index);
        }
        private void InitializeHexagons()
        {
            Rectangle clientRectangle = this.ClientRectangle;

            clientRectangle.Offset(0, -8);
            if (clientRectangle.Height < clientRectangle.Width)
            {
                clientRectangle.Inflate(-(clientRectangle.Width - clientRectangle.Height) / 2, 0);
            }
            else
            {
                clientRectangle.Inflate(0, -(clientRectangle.Height - clientRectangle.Width) / 2);
            }
            int hexagonWidth           = this.GetHexagonWidth(Math.Min(clientRectangle.Height, clientRectangle.Width));
            int centerOfMiddleHexagonX = (clientRectangle.Left + clientRectangle.Right) / 2;
            int centerOfMiddleHexagonY = (clientRectangle.Top + clientRectangle.Bottom) / 2 - hexagonWidth;

            this.hexagonElements[0].CurrentColor = Color.White;
            this.hexagonElements[0].SetHexagonPoints((float)centerOfMiddleHexagonX, (float)centerOfMiddleHexagonY, hexagonWidth);
            int index1 = 1;

            for (int index2 = 1; index2 < this.sectorMaximum; ++index2)
            {
                float yCoordinate = (float)centerOfMiddleHexagonY;
                float xCoordinate = (float)(centerOfMiddleHexagonX + hexagonWidth * index2);
                for (int index3 = 0; index3 < this.sectorMaximum - 1; ++index3)
                {
                    int num1 = (int)((double)hexagonWidth * (double)this.matrix2[index3]);
                    int num2 = (int)((double)hexagonWidth * (double)this.matrix1[index3]);
                    for (int index4 = 0; index4 < index2; ++index4)
                    {
                        double num3          = 0.936 * (double)(this.sectorMaximum - index2) / (double)this.sectorMaximum + 0.12;
                        float  colorQuotient = ColorServices.GetColorQuotient(xCoordinate - (float)centerOfMiddleHexagonX, yCoordinate - (float)centerOfMiddleHexagonY);
                        this.hexagonElements[index1].SetHexagonPoints(xCoordinate, yCoordinate, hexagonWidth);
                        this.hexagonElements[index1].CurrentColor = ColorServices.ColorFromRGBRatios((double)colorQuotient, num3, 1.0);
                        yCoordinate += (float)num1;
                        xCoordinate += (float)num2;
                        ++index1;
                    }
                }
            }
            clientRectangle.Y -= hexagonWidth + hexagonWidth / 2;
            this.InitializeGrayscaleHexagons(ref clientRectangle, hexagonWidth, ref centerOfMiddleHexagonX, ref centerOfMiddleHexagonY, ref index1);
        }
Exemple #4
0
        public static Color ColorFromRGBRatios(double value1, double value2, double value3)
        {
            int blue;
            int green;
            int red;

            if (value3 == 0.0)
            {
                int num;
                blue  = num = (int)(value2 * (double)byte.MaxValue);
                green = num;
                red   = num;
            }
            else
            {
                float num1 = value2 > 0.5 ? (float)(value2 + value3 - value2 * value3) : (float)(value2 + value2 * value3);
                float num2 = (float)(2.0 * value2) - num1;
                red   = ColorServices.GetColorChannelValue(num2, num1, (float)(value1 + 120.0));
                green = ColorServices.GetColorChannelValue(num2, num1, (float)value1);
                blue  = ColorServices.GetColorChannelValue(num2, num1, (float)(value1 - 120.0));
            }
            return(Color.FromArgb(red, green, blue));
        }