Пример #1
0
        private void GeneratePhiMatrix(Rect ParentRect, DrawingContext drawingContext, int maxLevel, int currentAngle = 0)
        {
            Pen BlackPen;

            if (maxLevel <= 0) return;

            int absCurrentAngle = currentAngle % 360;

            Point startPoint, drawPoint;
            double a = ParentRect.GetLongerLine(), a1 = a / GOLDEN_RATIO;
            Size newRectSize, newSquareSize;

            if (absCurrentAngle == 0)
            {
                startPoint = new Point(ParentRect.X + a1, ParentRect.Y);
                drawPoint = new Point(ParentRect.X, ParentRect.Y);

                newRectSize = new Size(a - a1, a1);
                newSquareSize = new Size(a1, a1);
            }
            else if (absCurrentAngle == 90)
            {
                startPoint = new Point(ParentRect.X, ParentRect.Y + a1);
                drawPoint = new Point(ParentRect.X, ParentRect.Y);

                newRectSize = new Size(a1, a - a1);
                newSquareSize = new Size(a1, a1);
            }
            else if (absCurrentAngle == 180)
            {
                startPoint = new Point(ParentRect.X, ParentRect.Y);
                drawPoint = new Point(ParentRect.X + a - a1, ParentRect.Y);

                newRectSize = new Size(a - a1, a1);
                newSquareSize = new Size(a1, a1);
            }
            else if (absCurrentAngle == 270)
            {
                startPoint = new Point(ParentRect.X, ParentRect.Y);
                drawPoint = new Point(ParentRect.X, ParentRect.Y + a - a1);

                newRectSize = new Size(a1, a - a1);
                newSquareSize = new Size(a1, a1);
            }
            else
            {
                throw new NotImplementedException();
            }

            BlackPen = new Pen(new SolidColorBrush(GoldenUtils.ColorStack[maxLevel % GoldenUtils.ColorStack.Count]), 1.5);

            drawingContext.DrawRectangle(Brushes.Transparent, BlackPen, new Rect(startPoint, newRectSize));
            drawingContext.DrawRectangle(Brushes.Transparent, BlackPen, new Rect(drawPoint, newSquareSize));

            GeneratePhiMatrix(new Rect(startPoint, newRectSize), drawingContext, --maxLevel, currentAngle);
        }
Пример #2
0
        private void GenerateGoldenSquares(Rect ParentRect, DrawingContext drawingContext, int maxLevel, int currentAngle = 0)
        {
            Pen BlackPen;

            if(maxLevel<=0) return;

            int absCurrentAngle = currentAngle%360;

            Point startPoint, drawPoint;
            double a = ParentRect.GetLongerLine(), a1 = a/GOLDEN_RATIO;
            Size newRectSize, newSquareSize;

            if (absCurrentAngle == 0)
            {
                startPoint = new Point(ParentRect.X + a1, ParentRect.Y);
                drawPoint = new Point(ParentRect.X, ParentRect.Y);

                newRectSize = new Size(a-a1, a1);
                newSquareSize = new Size(a1, a1);
            }
            else if (absCurrentAngle == 90)
            {
                startPoint = new Point(ParentRect.X, ParentRect.Y + a1);
                drawPoint = new Point(ParentRect.X, ParentRect.Y);

                newRectSize = new Size(a1, a - a1);
                newSquareSize = new Size(a1, a1);
            }
            else if (absCurrentAngle == 180)
            {
                startPoint = new Point(ParentRect.X, ParentRect.Y);
                drawPoint = new Point(ParentRect.X + a - a1, ParentRect.Y);

                newRectSize = new Size(a - a1, a1);
                newSquareSize = new Size(a1, a1);
            }
            else if (absCurrentAngle == 270)
            {
                startPoint = new Point(ParentRect.X, ParentRect.Y);
                drawPoint = new Point(ParentRect.X, ParentRect.Y + a - a1);

                newRectSize = new Size(a1, a - a1);
                newSquareSize = new Size(a1, a1);
            }
            else
            {
                throw new NotImplementedException();
            }

            BlackPen = new Pen(new SolidColorBrush(GoldenUtils.ColorStack[maxLevel % GoldenUtils.ColorStack.Count]), 1.5);

            drawingContext.DrawRectangle(Brushes.Transparent, BlackPen, new Rect(startPoint, newRectSize));
            drawingContext.DrawQuarterCicle(RedPen, Brushes.Transparent, new Rect(drawPoint, newSquareSize), absCurrentAngle + 180, 90);

            Rect square = new Rect(drawPoint, newSquareSize);
            drawingContext.DrawRectangle(Brushes.Transparent, BlackPen, square);
            FormattedText ft = new FormattedText(Math.Round(square.Size.Height, 3).ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), DipHelper.PtToDip(8), BlackPen.Brush);
            if(ft.Height < square.Height) drawingContext.DrawText(ft, new Point(square.X + square.Height/2.8, square.Y + square.Height/2.2));

            currentAngle += 90;

            GenerateGoldenSquares(new Rect(startPoint, newRectSize), drawingContext, --maxLevel, currentAngle);
        }