Ejemplo n.º 1
0
        protected static ColorCell[][] CreateColorCells(int row, int cols)
        {
            var res = new ColorCell[row][];

            for (var i = 0; i < row; i++)
            {
                res[i] = new ColorCell[cols];
            }
            return(res);
        }
Ejemplo n.º 2
0
        protected override void OnInitialize()
        {
            var width  = Convert.ToInt32(2 * CellRadius * CellColumns);
            var height = Convert.ToInt32(2 * CellRadius * CellRows) + 1;

            MinimumSize = new Size(width, height);

            Cells = CreateColorCells(_cellRows, _cellColumns);

            var interWidth = 2 * (int)(CellRadius * Math.Cos(MathUtility.DegToRad * 30.0)) + 1;

            Point start;

            var diameter = 2 * CellRadius;

            if (CellStyle == ColorCellStyle.Hexagon)
            {
                int matrixWidth;
                int matrixHeight;


                if (_cellRows == 1)
                {
                    matrixWidth  = _cellColumns * interWidth;
                    matrixHeight = diameter;

                    start = new Point(
                        (int)((Width - matrixWidth) / 2.0) + interWidth / 2,
                        (int)((Height - matrixHeight) / 2.0) + diameter / 2);
                }
                else
                {
                    matrixWidth  = (_cellColumns * 2 + 1) * (interWidth / 2) + _cellColumns;
                    matrixHeight = (int)(2 * CellRadius + (_cellRows - 1) * 1.5 * CellRadius);

                    //Start = new Point(
                    //(int)((Width - MatrixWidth) / 2.0),
                    //(int)((Height - MatrixHeight) / 2.0)
                    //);
                    start = new Point(
                        (int)((Width - matrixWidth) / 2.0) + interWidth / 2,
                        (int)((Height - matrixHeight) / 2.0) + diameter / 2);
                }
            }
            else
            {
                start = new Point(Width / 2 - (_cellColumns * CellRadius) + CellRadius,
                                  Height / 2 - _cellRows * CellRadius + CellRadius);
            }

            for (int row = 0; row < _cellRows; row++)
            {
                for (int col = 0; col < _cellColumns; col++)
                {
                    if (CellStyle == ColorCellStyle.Hexagon)
                    {
                        Point p = new Point(
                            start.X + interWidth * col,
                            (int)(start.Y + (CellRadius * 1.5) * row)
                            );

                        if (row % 2 != 0)
                        {
                            p.X += interWidth / 2;
                        }

                        Cells[row][col] = new ColorCell(p, CellRadius, System.Drawing.Color.Red, System.Drawing.Color.Black);
                    }
                    else
                    {
                        Point p = new Point(start.X + CellRadius * col * 2, start.Y + CellRadius * row * 2);
                        Cells[row][col] = new ColorCell(p, CellRadius, System.Drawing.Color.Red, System.Drawing.Color.Black);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected override void OnInitialize()
        {
            var interWidth = 2 * (int)(CellRadius * Math.Cos(MathUtility.DegToRad * 30.0));
            var width      = Convert.ToInt32(CellCount * interWidth);

            MinimumSize = new Size(width, width - interWidth);

            Cells = CreateColorCells(CellCount, CellCount);

            var diameter = 2 * CellRadius;

            var matrixWidth  = _cellCount * interWidth;
            var matrixHeight = (int)(2 * CellRadius + (_cellCount - 1) * 1.5 * CellRadius);

            var start = new Point(
                (int)((Width - matrixWidth) / 2.0),
                (int)((Height - matrixHeight) / 2.0) + diameter / 2);

            var chk = (_cellCount - 1) / 2;

            if (chk % 2 == 0)
            {
                start.X += interWidth / 2;
            }


            for (int row = 0; row < _cellCount; row++)
            {
                for (int col = 0; col < _cellCount; col++)
                {
                    var p = new Point(start.X + interWidth * col, (int)
                                      (start.Y + (CellRadius * 1.5) * row));

                    if (row % 2 != 0)
                    {
                        p.X += interWidth / 2;
                    }

                    Cells[row][col] = new ColorCell(p, CellRadius, System.Drawing.Color.Empty, System.Drawing.Color.Empty);
                }
            }


            var cnt = _cellCount / 2;

            var center = Cells[cnt][cnt].Center;

            var bigcellHeight = matrixWidth / 2 + CellRadius / 2;

            var bigCell = new ColorCell(center, bigcellHeight, System.Drawing.Color.Red, System.Drawing.Color.Black);

            _bigCellPoly = bigCell.Hexagon90();

            var cell = FindColorCell(center);

            if (cell != null)
            {
                cell.FillColor   = System.Drawing.Color.White;
                cell.BorderColor = System.Drawing.Color.Black;
            }

            for (int row = 0; row < _cellCount; row++)
            {
                for (int col = 0; col < _cellCount; col++)
                {
                    var currentPoint = Cells[row][col].Center;

                    if (MathUtility.InsidePolygon(_bigCellPoly, currentPoint))
                    {
                        var dist = Math.Sqrt(Math.Pow(center.X - currentPoint.X, 2) + Math.Pow(center.Y - currentPoint.Y, 2));

                        int x = currentPoint.X - center.X;
                        int y = currentPoint.Y - center.Y;

                        var h = (int)(new Point(x, y).AngleFromPoint());

                        var r = dist / ((_cellCount * interWidth) / 2d);
                        var l = (float)(1.0 - r);

                        Cells[row][col].FillColor = new HlsColor {
                            H = h, L = l, S = 1f
                        };
                        Cells[row][col].BorderColor = CellBorderColor;
                    }
                }
            }
        }