Example #1
0
        private void move(Turtle tut, int row, int pos, Label label, string player)
        {
            for (int i = 0; i <= row; i++)
            {
                pos++;
                label.Content = (pos);
                if ((pos == 11) || (pos == 31) || (pos == 51) || (pos == 71) || (pos == 91))
                {
                    tut.Left(90);
                    Thread.Sleep(250);
                    tut.Forward(100);
                    tut.Left(90);
                }
                else if ((pos == 21) || (pos == 41) || (pos == 61) || (pos == 81))
                {
                    Thread.Sleep(250);
                    tut.Right(90);
                    tut.Forward(100);
                    tut.Right(90);
                }
                else
                {
                    Thread.Sleep(250);
                    tut.Forward(100);
                }

                if (pos == 100)
                {
                    cw = new congratulations(player);
                    cw.Show();
                    this.Hide();
                }
            }
        }
Example #2
0
        public static bool UpdateBullet(Turtle Bull, double p, Label txt, double wind, Random rng, Image enemy) // p == power
        {
            Color k = Bull.ColorUnderTurtle;

            wind = rng.Next(-30, 30);
            if (wind > 0) txt.Content = $"Wind:  {wind}km East";
            else txt.Content = $"Wind:  {-1 * wind}km West";
            p += wind;
            while (k.ToString() == "#FF3F61FE" || k.ToString() == "#FFFFFFFF" || k.ToString() == "#FF000000" || k.ToString() == "#FF00A2E8" || k.ToString() == "#FF121214" || k.ToString() == "#FF12121E" || k.ToString() == "#FF121232" || k.ToString() == "#FF12125A" || k.ToString() == "#FF121278" || k.ToString() == "#FF121296" || k.ToString() == "#FF12121E" || k.ToString() == "#FF121282" || k.ToString() == "#FF1212A0" || k.ToString() == "#FF12126E") //Checking the bullet is in the air
            {
                    k = Bull.ColorUnderTurtle;
                    if (Bull.Heading < 90 || (Bull.Heading > 180))
                    {
                        Bull.Forward(p / 10);
                        Bull.Heading += 2;
                        if (Bull.Position.X > Canvas.GetLeft(enemy) + 10 && Bull.Position.Y > Canvas.GetTop(enemy) + 50)
                        {
                            return true;
                        }
                    }
                    else
                    {
                        Bull.Forward(p / 10);
                        if (Bull.Position.X > Canvas.GetLeft(enemy) +10 && Bull.Position.Y > Canvas.GetTop(enemy)+50)
                        {
                            return true;
                        }
                    }
                }
                return false;
      
            }
Example #3
0
        }                                  // Let variable tess refer to the new turtle.

        private void btnDemo1_Click(object sender, RoutedEventArgs e)
        {
            tess.Forward(80.0);
            tess.Right(90.0);
            tess.Forward(30.0);
            tess.Right(90.0);
        }
Example #4
0
        const double trunk_ratio = 0.29;       // How big is the trunk relative to whole tree?

        public void drawTree(int order, double theta, double treeSize)
        {
            double trunkSize = treeSize * trunk_ratio;  // length of trunk

            tess.Forward(trunkSize);                    // always draw the trunk

            if (order > 0)                              // must we also draw subtrees?
            {
                double branchSize = treeSize - trunkSize;
                tess.Left(theta);
                drawTree(order - 1, theta, branchSize);
                tess.Right(2 * theta);
                //if (order == 7)
                //{
                //    tess.LineBrush = Brushes.Green;
                //    drawTree(order - 1, theta, branchSize);
                //    tess.LineBrush = Brushes.Magenta;
                //}
                //else
                {
                    drawTree(order - 1, theta, branchSize);
                }

                tess.Left(theta);
            }

            tess.Forward(-trunkSize);          // make sure we end up where we started.
        }
Example #5
0
        public void DrawBoard(Canvas playground)
        {
            Rabs = new Turtle(playground, 80, 80);

            Rabs.BrushWidth = 4;

            for (int i = 0; i < 3; i++)
            {
                Rabs.Goto(80 * (i + 1), 80 * (i + 1));
                for (int x = 0; x < 4; x++)
                {
                    Rabs.Forward(480 - (i * 160));
                    Rabs.Right(90);
                }
            }
            Rabs.Goto(80, 80);
            Rabs.Heading = 90;

            for (int i = 0; i < 4; i++)
            {
                Rabs.Forward(240);
                Rabs.Left(90);
                Rabs.Forward(160);
                Rabs.Right(90);
                Rabs.Forward(80);
                Rabs.Right(45);
                Rabs.Forward(Math.Sqrt(160 * 160 * 2));
                Rabs.Left(135);
            }
        }
Example #6
0
 // Draw one hand of the clock using turtle t, at the given angle, the given length,
 // the given brush width and brush.
 private void drawHand(Turtle t, double angle, double sz, double width, Brush b)
 {
     t.LineBrush  = b;
     t.Heading    = angle - 90;
     t.BrushWidth = width;
     t.Forward(sz);
     t.Forward(-sz);
 }
Example #7
0
 void DrawShape()
 {
     tess.Heading = 0;
     for (int i = 0; i < 5; i = i + 1)
     {
         tess.Forward(200);
         tess.Right(144);
     }
 }
Example #8
0
 void Circle(double size)
 {
     tess.WarpTo(760 / 2, 500);
     tess.BrushWidth = sliBrushWidth.Value;
     for (int i = 0; i < 360; i = i + 1)
     {
         tess.Forward(size);
         tess.Right(360 - 1);
     }
 }
 /// <summary>
 /// Draws footprints on the canvas
 /// </summary>
 void DrawStamps()
 {
     for (int i = 0; i < 12; i++)
     {
         tess.Forward(75);
         tess.Stamp();
         tess.Forward(-75);
         tess.Left(30);
     }
 }
 /// <summary>
 /// Event handler for the Go button
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnGo_Click(object sender, RoutedEventArgs e)
 {
     tess.Forward(75);
     tess.Stamp();
     tess.Forward(-75);
     tess.Left(30);
     tess.Forward(75);
     tess.Stamp();
     tess.Forward(-75);
 }
Example #11
0
 public void drawRectangle(Turtle tx, double wSz, double hSz)
 {
     for (int i = 0; i < 2; i = i + 1)
     {
         tx.Forward(wSz);
         tx.Right(90.0);
         tx.Forward(hSz);
         tx.Right(90.0);
     }
 }
Example #12
0
 private void button_Click(object sender, RoutedEventArgs e)
 {
     tess.Forward(80.0);   // Make Tess draw a square
     tess.Right(90.0);
     tess.Forward(80.0);
     tess.Right(90.0);
     tess.Forward(80.0);
     tess.Right(90.0);
     tess.Forward(80.0);
     tess.Right(90.0);
 }
Example #13
0
 private void draw_bar(Turtle t, int height)
 {
     // Get turtle t to draw one bar, of height.
     t.Left(90);
     t.Forward(height);     // Draw up the left side
     t.Right(90);
     t.Stamp(String.Format("{0}", height), 0, height > 0 ? -24 : 0);
     t.Forward(40);         // Width of bar, along the top
     t.Right(90);
     t.Forward(height);     // And down again!
     t.Left(90);            // Put the turtle facing the way we found it.
     t.Forward(10);         // Leave small gap after each bar
 }
Example #14
0
 private void button1_Click(object sender, RoutedEventArgs e)
 {
     // Draw a broken line by picking up the brush in the middle
     alex.Forward(40.0);
     alex.BrushDown = false;
     alex.Forward(40.0);
     alex.BrushDown = true;
     alex.Forward(40.0);
     alex.Right(95);
 }
Example #15
0
        private void TrojuholnikSpiral_Click(object sender, EventArgs e)
        {
            try
            {
                float strana = float.Parse(Input.Text);
                Turtle.ShowTurtle = false;
                Turtle.PenSize    = 1;
                Turtle.RotateTo(180);

                while (strana > 1)
                {
                    Turtle.PenUp();
                    Turtle.Forward((float)Math.Sqrt(3) / 3f * strana);
                    Turtle.Rotate(150);
                    Turtle.PenDown();

                    for (int i = 0; i < 3; i++)
                    {
                        Turtle.Forward(strana);
                        Turtle.Rotate(120);
                    }
                    Turtle.Rotate(30);
                    Turtle.Forward((float)Math.Sqrt(3) / 3f * strana);
                    Turtle.Rotate(186);
                    strana -= (strana / 100) * 2;
                }
            }

            catch
            {
                MessageBox.Show("Ďalej to už nepôjde, formát: strana(float)");
            }
        }
Example #16
0
        private void Hexagon_Click(object sender, EventArgs e)
        {
            try
            {
                float strana = float.Parse(Input.Text);
                Turtle.ShowTurtle = false;
                Turtle.PenSize    = 1;
                Turtle.RotateTo(90);

                for (int k = 0; k < 6; k++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        Turtle.Forward(strana);
                        Turtle.Rotate(60);
                    }

                    Turtle.Forward(strana);
                    Turtle.Rotate(-60);
                }
            }

            catch
            {
                MessageBox.Show("Ďalej to už nepôjde, formát: strana(float)");
            }
        }
Example #17
0
        private void Ciara2_Click(object sender, EventArgs e)
        {
            try
            {
                string[] split   = Input.Text.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                float    grow    = float.Parse(split[0]);
                int      pocet   = Convert.ToInt32(split[1]);
                float    medzera = float.Parse(split[2]);
                Turtle.ShowTurtle = false;
                Turtle.PenSize    = 1;
                Turtle.RotateTo(90);

                for (int k = 0; k < pocet; k++)
                {
                    Turtle.Forward(grow);
                    Turtle.PenUp();
                    Turtle.Forward(medzera);
                    Turtle.PenDown();
                    grow += grow;
                }
            }

            catch
            {
                MessageBox.Show("Ďalej to už nepôjde, formát: plus-dĺžka(float), počet-čiar(int), veľkosť-medzery(float)");
            }
        }
Example #18
0
        private void buttonDraw_Click(object sender, EventArgs e)
        {
            //Turtle.Rotate(30);
            //Turtle.Forward(200);
            //Turtle.Rotate(120);
            //Turtle.Forward(200);
            //Turtle.Rotate(120);
            //Turtle.Forward(200);

            Turtle.PenColor = Color.Blue;

            // Assign a delay to visualize the drawing process
            Turtle.Delay = 200;

            // Draw a equilateral triangle
            Turtle.Rotate(30);
            Turtle.Forward(200);
            Turtle.Rotate(120);
            Turtle.Forward(200);
            Turtle.Rotate(120);
            Turtle.Forward(200);

            // Draw a line in the triangle
            Turtle.Rotate(-30);
            Turtle.PenUp();
            Turtle.Backward(50);
            Turtle.PenDown();
            Turtle.Backward(100);
            Turtle.PenUp();
            Turtle.Forward(150);
            Turtle.PenDown();
            Turtle.Rotate(30);
        }
Example #19
0
        private async void TurtleButton_Click(object sender, EventArgs e)
        {
            string[] Moves = File.ReadAllLines("Moves.txt");
            for (int i = 0; i < Moves.Length; i++)
            {
                switch (Moves[i])
                {
                case "Up":
                    Turtle.RotateTo(0);
                    Turtle.Forward(25);
                    break;

                case "Down":
                    Turtle.RotateTo(180);
                    Turtle.Forward(25);
                    break;

                case "Left":
                    Turtle.RotateTo(-90);
                    Turtle.Forward(25);
                    break;

                case "Right":
                    Turtle.RotateTo(90);
                    Turtle.Forward(25);
                    break;
                }
                await Task.Delay(500);
            }
        }
 private void button1_Click(object sender, EventArgs e)
 {
     Turtle.PenColor = Color.Red;
     for (int i = 0; i < 25; i++)
     {
         Turtle.Forward(i * 10);
         Turtle.Rotate(120);
         Turtle.Forward(i * 10);
         Turtle.Rotate(120);
     }
     Turtle.Rotate(120);
     for (int i = 0; i < 25; i++)
     {
         Turtle.Forward(i * 10);
         Turtle.Rotate(120);
         Turtle.Forward(i * 10);
         Turtle.Rotate(120);
     }
     Turtle.Forward(250);
     for (int i = 0; i < 25; i++)
     {
         Turtle.Forward(i * 10);
         Turtle.Rotate(120);
         Turtle.Forward(i * 10);
         Turtle.Rotate(120);
     }
 }
Example #21
0
        private void StvorecSpin_Click(object sender, EventArgs e)
        {
            try
            {
                float strana = float.Parse(Input.Text);
                Turtle.ShowTurtle = false;
                Turtle.PenSize    = 1;

                for (int k = 0; k < 3; k++)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        Turtle.Forward(strana);
                        Turtle.Rotate(90);
                    }

                    Turtle.Rotate(-6);
                }
            }

            catch
            {
                MessageBox.Show("Ďalej to už nepôjde, formát: strana(float)");
            }
        }
Example #22
0
    public void visit(BackWard backWard)
    {
        backWard.expression.accept(this);
#if (UNCOMMENT)
        Turtle.Forward(-backWard.expression.output);
#endif
    }
Example #23
0
    public void visit(Forward forward)
    {
        forward.expression.accept(this);
#if (UNCOMMENT)
        Turtle.Forward(forward.expression.output);
#endif
    }
Example #24
0
        public override void MoveTurtle(string instructions, float distanceUnit)
        {
            ExpressiveRangeLogger.RecordPosition();
            for (int i = 0; i < instructions.Length; i++)
            {
                switch (instructions[i])
                {
                case 'F':
                case 'G':
                    Turtle.Forward(distanceUnit);
                    break;

                case '-':
                    Turtle.Rotate(120);
                    break;

                case '+':
                    Turtle.Rotate(-120);
                    break;
                }
                ExpressiveRangeLogger.RecordPosition();
                ProgressBar.Value = i;
            }
            base.MoveTurtle(instructions, distanceUnit);
        }
Example #25
0
        private void Schody_Click(object sender, EventArgs e)
        {
            try
            {
                string[] split  = Input.Text.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                float    strana = float.Parse(split[0]);
                int      pocet  = Convert.ToInt32(split[1]);
                Turtle.ShowTurtle = false;
                Turtle.PenSize    = 1;
                Turtle.RotateTo(90);

                for (int k = 0; k < pocet; k++)
                {
                    Turtle.Forward(strana);
                    Turtle.Rotate(-90);
                    Turtle.Forward(strana);
                    Turtle.RotateTo(90);
                }
            }

            catch
            {
                MessageBox.Show("Ďalej to už nepôjde, formát: strana(float), počet(int)");
            }
        }
        private void buttonSun_Click(object sender, EventArgs e)
        {
            //for (int z = 0; z < 40; z++)
            //{


            //    for (int i = 0; i < 5; i++)
            //    {
            //        Turtle.Rotate(350);
            //        Turtle.Forward(i * 1);

            //        for (int k = 0; k < 6; k++)
            //        {
            //            Turtle.Rotate(350);
            //            Turtle.Forward(k * 1);
            //        }
            //    }
            //}
            Turtle.Delay = 100;
            for (int i = 0; i < 38; i++)
            {
                Turtle.Rotate(30);
                Turtle.Forward(200);
                Turtle.Rotate(5);
                Turtle.Backward(200);
                Turtle.Rotate(90);
                Turtle.Forward(200);
                Turtle.Rotate(5);
                Turtle.Backward(200);
                Turtle.Rotate(60);
            }
        }
Example #27
0
        public override void MoveTurtle(string instructions, float distanceUnit)
        {
            ExpressiveRangeLogger.RecordPosition();
            for (int i = 0; i < instructions.Length; i++)
            {
                switch (instructions[i])
                {
                case '0':
                    Turtle.Forward(distanceUnit / 2);
                    break;

                case '1':
                    Turtle.Forward(distanceUnit);
                    break;

                case '[':
                    PushTurtle();
                    Turtle.Rotate(-45);
                    break;

                case ']':
                    PopTurtle();
                    Turtle.Rotate(45);
                    break;
                }
                ExpressiveRangeLogger.RecordPosition();
                ProgressBar.Value = i;
            }
            base.MoveTurtle(instructions, distanceUnit);
        }
Example #28
0
        private void buttonDraw_Click(object sender, EventArgs e)
        {
            Turtle.Delay = 300;

            for (int i = 0; i <= 3; i++)
            {
                // Draw a equilateral triangle
                Turtle.Rotate(30);
                Turtle.Forward(200);
                Turtle.Rotate(120);
                Turtle.Forward(200);
                Turtle.Rotate(120);
                Turtle.Forward(200);

                // Draw a line in the triangle
                Turtle.Rotate(-30);
                Turtle.PenUp();
                Turtle.Backward(50);
                Turtle.PenDown();
                Turtle.Backward(100);
                Turtle.PenUp();
                Turtle.Forward(150);
                Turtle.PenDown();
                Turtle.Rotate(30);
            }
        }
Example #29
0
        private void buttonTriangle_Click(object sender, EventArgs e)
        {
            Turtle.Delay = 200;
            for (int i = 0; i < 22; i++)
            {
                Turtle.Forward(100);
                Turtle.Rotate(120);

                for (int n = 0; n < i; n++)
                {
                    Turtle.Forward(10);
                }
            }
            for (int i = 0; i < 22; i++)
            {
                Turtle.Forward(100);
                Turtle.Rotate(120);

                for (int n = 0; n < i; n++)
                {
                    Turtle.Forward(10);
                }
            }
            for (int i = 0; i < 22; i++)
            {
                Turtle.Forward(100);
                Turtle.Rotate(120);

                for (int n = 0; n < i; n++)
                {
                    Turtle.Forward(10);
                }
            }
        }
Example #30
0
        private void DrawLevel(float parentSize, int numberOfLevels)
        {
            // Satellites
            var satelliteSize = parentSize / 2;

            Turtle.Forward(parentSize / 2);
            Turtle.Rotate(-60);
            DrawEquilateralTriangle(satelliteSize, numberOfLevels);
            Turtle.Rotate(60);

            --numberOfLevels;

            if (numberOfLevels > 0)
            {
                DrawLevel(satelliteSize, numberOfLevels);
                Turtle.Backward(parentSize - satelliteSize / 2);

                DrawLevel(satelliteSize, numberOfLevels);

                Turtle.Backward(satelliteSize / 2);
                Turtle.Rotate(-60);
                Turtle.Forward(parentSize / 2);
                Turtle.Rotate(60);

                DrawLevel(satelliteSize, numberOfLevels);

                // Now back to where we started...
                Turtle.Rotate(-60);
                Turtle.Forward(-parentSize / 2);
                Turtle.Rotate(60);
                Turtle.Backward(-satelliteSize / 2);
            }
        }
Example #31
0
        public void TestForward()
        {
            Turtle t = new Turtle();
            t.Forward(10f);

            Assert.AreEqual(10f, t.X);
            Assert.AreEqual(0f, t.Y);
        }
Example #32
0
        public void TestTurnMove()
        {
            Turtle t = new Turtle();
            t.Left(45);
            t.Forward(10);

            Assert.AreEqual(7.07, t.X, 0.002);
            Assert.AreEqual(7.07, t.Y, 0.002);

            t.Undo();
            t.Left(45);
            t.Forward(10);

            Assert.AreEqual(0, t.X, 0.002);
            Assert.AreEqual(10, t.Y);

            t.Undo();
            t.Left(45);
            t.Forward(10);

            Assert.AreEqual(-7.07, t.X, 0.002);
            Assert.AreEqual(7.07, t.Y, 0.002);
        }
    public static void Interpret(
        int segmentAxisSamples,
        int segmentRadialSamples,
        float segmentWidth,
        float segmentHeight,
        float leafSize,
        int leafAxialDensity,
        int leafRadialDensity,
        bool useFoliage,
        bool narrowBranches,
        Material leafMaterial,
        Material trunkMaterial,
        float angle,
        string moduleString,
        out GameObject leaves,
        out GameObject trunk)
    {
        leaves = new GameObject("Leaves");
        trunk = new GameObject("Trunk");

        GameObject leafBillboard = CreateLeafBillboard(leafSize, leafMaterial);

        int chunkCount = 0;
        Mesh currentMesh = new Mesh();
        Dictionary<int, Mesh> segmentsCache = new Dictionary<int, Mesh>();
        Turtle current = new Turtle(Quaternion.identity, Vector3.zero, new Vector3(0, segmentHeight, 0));
        Stack<Turtle> stack = new Stack<Turtle>();
        for (int i = 0; i < moduleString.Length; i++)
        {
            string module = moduleString[i] + "";
            if (module == "F")
            {
                CreateSegment(
                    segmentAxisSamples,
                    segmentRadialSamples,
                    segmentWidth,
                    segmentHeight,
                    narrowBranches,
                    trunkMaterial,
                    current,
                    stack.Count,
                    ref currentMesh,
                    ref chunkCount,
                    trunk,
                    segmentsCache);
                current.Forward();
            }
            else if (module == "+")
            {
                current.RotateZ(angle);
            }
            else if (module == "-")
            {
                current.RotateZ(-angle);
            }
            else if (module == "&")
            {
                current.RotateX(angle);
            }
            else if (module == "^")
            {
                current.RotateX(-angle);
            }
            else if (module == "\\")
            {
                current.RotateY(angle);
            }
            else if (module == "/")
            {
                current.RotateY(-angle);
            }
            else if (module == "|")
            {
                current.RotateZ(180);
            }
            else if (module == "[")
            {
                stack.Push(current);
                current = new Turtle(current);
            }
            else if (module == "]")
            {
                if (useFoliage)
                    AddFoliageAt(
                        segmentWidth,
                        segmentHeight,
                        leafAxialDensity,
                        leafRadialDensity,
                        current,
                        leafBillboard,
                        leaves);
                current = stack.Pop();
            }
        }
        CreateNewChunk(currentMesh, ref chunkCount, trunkMaterial, trunk);
        GameObject.Destroy(leafBillboard);
    }