Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();
            var foxDraw = new FoxDraw(canvas);
            // create a line drawing function that takes 2 parameters:
            // the x and y coordinates of the line's starting point
            // and draws a line from that point to the center of the canvas.
            // fill the canvas with lines from the edges, every 20 px, to the center.

            double startX = 0;
            double startY = 0;

            Random rng = new Random();
            //var centrePosition = new Point(rng.Next(0, 700), rng.Next(0, 700));

            var centrePosition = new Point(canvas.Width / 2, canvas.Height / 2);

            AllLinesToCenter(startX, startY, centrePosition);

            void AllLinesToCenter(double x, double y, Point centre)
            {
                //var centre = new Point(canvas.Width / 2, canvas.Height / 2);

                double startPositionX = x;
                double startPositionY = y;

                var startPoint = new Point(0, 0);

                //Top Row
                for (int i = 0; i < canvas.Width / 20; i++)
                {
                    startPositionX = i * 20;
                    startPoint     = new Point(startPositionX, startPositionY);
                    foxDraw.DrawLine(startPoint, centre);
                }

                //Right Row
                for (int j = 0; j < canvas.Height / 20; j++)
                {
                    startPositionY = j * 20;
                    startPoint     = new Point(startPositionX, startPositionY);
                    foxDraw.DrawLine(startPoint, centre);
                }

                //Row bottom
                for (int k = 0; k < canvas.Width / 20; k++)
                {
                    startPositionX = k * 20;
                    startPoint     = new Point(startPositionX, startPositionY);
                    foxDraw.DrawLine(startPoint, centre);
                }

                //Row Left
                for (int j = 0; j < canvas.Height / 20; j++)
                {
                    startPositionY = j * 20;
                    startPoint     = new Point(0, startPositionY);
                    foxDraw.DrawLine(startPoint, centre);
                }
            }
        }
Ejemplo n.º 2
0
 public static void DrawToCenterFrom(double x, double y, Point centre, FoxDraw foxDraw)
 {
     foxDraw.StrokeColor(Colors.Green);
     foxDraw.DrawLine(new Point(x, y), centre);
 }
Ejemplo n.º 3
0
        public MainWindow()
        {
            InitializeComponent();

            var foxDraw = new FoxDraw(canvas);

            int angle = 0;

            DrawPyramidWithWidth(-50, 5);

            void DrawPyramidWithWidth(int triangleSize, int pyramidWidth)
            {
                double centreX = ((canvas.Width / 2) - (triangleSize * pyramidWidth) / 2);

                //Triangle Points

                Dictionary <string, Point> TrianglePoints = new Dictionary <string, Point>();

                var left  = new Point(centreX, canvas.Height);
                var top   = new Point(left.X + triangleSize * Math.Cos(angle + Math.PI / 3), left.Y + triangleSize * Math.Sin(angle + Math.PI / 3));
                var right = new Point(left.X + triangleSize * Math.Cos(angle), left.Y + triangleSize * Math.Sin(angle));

                void resetXpositions()
                {
                    left.X  = centreX;
                    top.X   = left.X + triangleSize * Math.Cos(angle + Math.PI / 3);
                    right.X = left.X + triangleSize * Math.Cos(angle);
                }

                void drawOneTriangle()
                {
                    foxDraw.DrawLine(left, top);
                    foxDraw.DrawLine(top, right);
                    foxDraw.DrawLine(right, left);
                }

                void shiftTriangleUp()
                {
                    left.Y  += triangleSize;
                    top.Y   += triangleSize;
                    right.Y += triangleSize;
                }

                void shiftTriangleRightBy(double multiplier)
                {
                    left.X  += (triangleSize * multiplier);
                    top.X   += (triangleSize * multiplier);
                    right.X += (triangleSize * multiplier);
                }

                void drawAmountOfTriangles(int number)
                {
                    for (int j = 1; j < number; j++)
                    {
                        shiftTriangleRightBy(1);
                        drawOneTriangle();
                    }
                }

                for (int i = 1; i < pyramidWidth; i++)
                {
                    shiftTriangleUp();
                    resetXpositions();
                    //shiftTriangleRightBy(1);

                    drawAmountOfTriangles(pyramidWidth - i);
                }
            }
        }