Esempio n. 1
0
        static void Sierpinsky()
        {
            var Vertices = new Tuple <int, int>[] { new Tuple <int, int>(0, 600), new Tuple <int, int>(300, 0), new Tuple <int, int>(600, 600) };
            var p        = new Tuple <int, int>(300, 300);

            GraphicsWindow.Show();
            for (int i = 0; i < 100000; i++)
            {
                GraphicsWindow.SetPixel(p.Item1, p.Item2, "Black");
                var v = Pick(Vertices);
                p = new Tuple <int, int>((p.Item1 + v.Item1) / 2, (p.Item2 + v.Item2) / 2);
            }
        }
        static void Main(string[] args)
        {
            GraphicsWindow.Show();



            GraphicsWindow.SetPixel(10, 10, "red");

            int x1 = 312, y1 = 10,
                x2 = 10, y2 = 430,
                x3 = 610, y3 = 430
            ;

            GraphicsWindow.SetPixel(x1, y1, "red");
            GraphicsWindow.SetPixel(x2, y2, "red");
            GraphicsWindow.SetPixel(x3, y3, "red");

            int size = 1;

            GraphicsWindow.DrawEllipse(x1 - size / 2, y1 - size / 2, size, size);
            GraphicsWindow.DrawEllipse(x2 - size / 2, y2 - size / 2, size, size);
            GraphicsWindow.DrawEllipse(x3 - size / 2, y3 - size / 2, size, size);
            Random random = new Random();

            GraphicsWindow.MouseDown += () =>
            {
                int x = x1, y = y1;
                for (int i = 0; i < 10000; i++)
                {
                    switch (random.Next(3))
                    {
                    case 0: x = (x + x1) / 2; y = (y + y1) / 2; break;

                    case 1: x = (x + x2) / 2; y = (y + y2) / 2; break;

                    case 2: x = (x + x3) / 2; y = (y + y3) / 2; break;
                    }
                    //GraphicsWindow.DrawEllipse(x - size / 2, y - size / 2, size, size);
                    GraphicsWindow.SetPixel(x, y, "red");
                }



                //GraphicsWindow.DrawEllipse(
                //    x: GraphicsWindow.MouseX - size / 2 ,
                //    y: GraphicsWindow.MouseY - size / 2,
                //    width: size,
                //    height: size);
            };
        }
Esempio n. 3
0
        // Szierpinsky Triangle
        static void Szierpinsky()
        {
            GraphicsWindow.Show();
            int x = 100, y = 100;
            var Rnd = new Random();

            for (int i = 0; i < 100000; i++)
            {
                GraphicsWindow.SetPixel(x, y, "Black");
                var r = Rnd.Next(1, 30);
                if (r < 10)
                {
                    Move(ref x, ref y, 100, 500);
                }
                else if (r < 20)
                {
                    Move(ref x, ref y, 600, 500);
                }
                else
                {
                    Move(ref x, ref y, 350, 100);
                }
            }
        }
Esempio n. 4
0
        // Analyseert de lijst en voert bijbehorende commando's uit.
        private static void AnalyseAndPerformActions(List <string> commandList)
        {
            for (var i = 0; i < commandList.Count; i++)
            {
                switch (commandList[i])
                {
                case "fd":
                case "forward":
                    Turtle.Move(GetNextNumber(i, commandList));
                    UpdatePositionVariables();
                    i += lengthOfNumericalInput;
                    break;

                case "bk":
                case "backward":
                    Turtle.Move(-GetNextNumber(i, commandList));
                    UpdatePositionVariables();
                    i += lengthOfNumericalInput;
                    break;

                case "rt":
                case "turn":
                    Turtle.Turn(GetNextNumber(i, commandList));
                    variables["angle"] = Turtle.Angle;
                    i += lengthOfNumericalInput;
                    break;

                case "lt":
                    Turtle.Turn(-GetNextNumber(i, commandList));
                    variables["angle"] = Turtle.Angle;
                    i += lengthOfNumericalInput;
                    break;

                case "wait":
                    System.Threading.Thread.Sleep((int)System.Math.Round(GetNextNumber(i, commandList) * 1000 / 60));
                    i += lengthOfNumericalInput;
                    break;

                case "speed":
                    Turtle.Speed       = GetNextNumber(i, commandList);
                    variables["speed"] = Turtle.Speed;
                    i += lengthOfNumericalInput;
                    break;

                case "msg":
                case "message":
                case "print":
                    if (i + 1 < commandList.Count)
                    {
                        TextWindow.WriteLine(RemoveBrackets(commandList[i + 1]));
                        i++;
                    }
                    else
                    {
                        ThrowException(5);
                    }
                    break;

                case "line":
                    SplitMultiNumberList(i, commandList, 4);

                    GraphicsWindow.DrawLine(multiNumberList[0], multiNumberList[1], multiNumberList[2], multiNumberList[3]);
                    i++;
                    break;

                case "setpos":
                    SplitMultiNumberList(i, commandList, 2);
                    Turtle.X = multiNumberList[0];
                    Turtle.Y = multiNumberList[1];
                    UpdatePositionVariables();
                    i++;
                    break;

                case "setpc":
                    SplitMultiNumberList(i, commandList, fromPenColor: true);

                    GraphicsWindow.PenColor = GraphicsWindow.GetColorFromRGB(
                        multiNumberList[0], multiNumberList[1], multiNumberList[2]);
                    i++;
                    break;

                case "setbc":
                    SplitMultiNumberList(i, commandList);

                    GraphicsWindow.BackgroundColor = GraphicsWindow.GetColorFromRGB(
                        multiNumberList[0], multiNumberList[1], multiNumberList[2]);
                    i++;
                    break;

                case "hide":
                case "hideturtle":
                case "ht":
                    Turtle.Hide();
                    turtleIsHidden = true;
                    break;

                case "show":
                case "showturtle":
                case "st":
                    if (turtleIsHidden)
                    {
                        Turtle.Show();
                    }

                    turtleIsHidden = false;
                    break;

                case "pu":
                case "penup":
                    Turtle.PenUp();
                    break;

                case "pd":
                case "pendown":
                    Turtle.PenDown();
                    break;

                case "file":
                    if (i + 1 < commandList.Count)
                    {
                        DrawFromFile(RemoveBrackets(commandList[i + 1]));
                        i++;
                    }
                    else
                    {
                        ThrowException(5);
                    }
                    break;

                case "setorientation":
                    Turtle.Angle       = GetNextNumber(i, commandList);
                    variables["angle"] = Turtle.Angle;
                    i += lengthOfNumericalInput;
                    break;

                case "setpx":
                case "setpixel":
                    SplitMultiNumberList(i, commandList, 2);

                    GraphicsWindow.SetPixel(multiNumberList[0], multiNumberList[1], GraphicsWindow.PenColor);
                    i++;
                    break;


                case "repeat":
                    i += RepeatCommands(i, commandList);
                    break;

                case "for":
                    ForLoop(i, commandList);
                    i += 2;
                    break;

                case "while":
                    WhileLoop(i, commandList);
                    i += 2;
                    break;

                case "circle":
                    int circleRadius = (int)GetNextNumber(i, commandList);
                    GraphicsWindow.DrawEllipse(Turtle.X - circleRadius, Turtle.Y - circleRadius, circleRadius * 2, circleRadius * 2);
                    i += lengthOfNumericalInput;
                    break;

                case "cs":
                    ResetTurtle();
                    break;

                case "ct":
                    TextWindow.Clear();
                    break;

                case "help":
                    PrintHelp();
                    break;

                case "if":
                    i += CompareInputs(i, commandList);
                    break;

                case "make":
                    AddVariable(i, commandList);
                    i += lengthOfNumericalInput + 1;
                    break;

                case "to":
                    i += ToCommandBase(i, commandList) + 2;
                    break;

                default:
                    if (toShortcuts.ContainsKey(commandList[i]))
                    {
                        AnalyseAndPerformActions(toShortcuts[commandList[i]]);
                    }
                    else if (commandList[i].StartsWith(":"))
                    {
                        TextWindow.WriteLine(GetNextNumber(i, commandList, 0));
                        i += lengthOfNumericalInput - 1;
                    }
                    else
                    {
                        ThrowException(0, commandList[i]);
                    }
                    break;
                }
            }
        }