M
M
Michael Sne Bjorn Palagin2017-07-02 20:56:42
C++ / C#
Michael Sne Bjorn Palagin, 2017-07-02 20:56:42

Turtle rotation +15 degrees every cycle, how to implement?

Hello. I am new to the C# language, I am still taking courses from MVA, they asked a DZ there, I completed it, but after a couple of lessons, having learned about new things, I decided to shorten the code of that DZ and make it better ( in my opinion ). And actually I came across one problem that is still incomprehensible to me :(
In general, if I remove the cycle in the Main method, then my turtle draws a line 75, then rotates by -45 degrees and draws another line 75, after which it returns to the starting point. Here I need make her next move be, draw line 75, rotate by -45 + 15 = -30 (her new angle of rotation) and draw line 75, return to the starting point and do this 7
times.Here is the code:

static void Main(string[] args)
        {
            int n = -45;
            int len = 150;
            Turtle.Speed = 10;

            for (int i = n; i <= 45; i++)
            {
                Draw(len, n);
            }

        }

        static void Draw(int len, int n)
        {
            int[] array = new int [2];

            for (int i = 0; i < 2; i++)
            {
                Turtle.Move(len / 2);
                Turtle.Turn(array[i] = n);
            }

            Turtle.Turn(180 - n);

            for (int i = 2 - 1; i >= 0; i--)
            {
                Turtle.Move(len / 2);
                Turtle.Turn(-array[i]);
            }

            Turtle.Turn(-180 + n);
        }

Once again, I ask in advance, do not throw slippers. I am quite new to the C# language.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael Sne Bjorn Palagin, 2017-07-02
@ven000mus

Doper himself :) and did what he wanted ...
New code:

static void Main(string[] args)
        {
            int ang = -60;
            int new_ang = 15;
            int len = 150;
            Turtle.Speed = 10;


            for (int i = 0; i <= 6; i++)
            {
                Draw(len, ang = ang + new_ang);
            }


        }

        static void Draw(int len, int ang)
        {
            int[] array = new int [2];

            for (int i = 0; i < 2; i++)
            {
                Turtle.Move(len / 2);
                Turtle.Turn(array[i] = ang);
            }

            Turtle.Turn(180 - ang);

            for (int i = 2 - 1; i >= 0; i--)
            {
                Turtle.Move(len / 2);
                Turtle.Turn(-array[i]);
            }

            Turtle.Turn(-180 + ang);
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question