Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Start:
- string koch = "F";
- // Rule: F -> F+F-F-F+F
- Func<string, string> transform = x => x.Replace("F", "F+F-F-F+F");
- // Fractal length:
- int length = 3;
- // Intialize the location and direction of the turtle:
- string command = @"home
- setxy 10 340
- right 90
- ";
- // Recursive definition to generate Logo commands:
- command += Enumerable.Range(1, length)
- .Select(k => koch = transform(koch))
- .Last()
- .Replace("F", "forward 15")
- .Replace("+", String.Format("{0}Left 90{1}", Environment.NewLine, Environment.NewLine))
- .Replace("-", String.Format("{0}Right 90{1}", Environment.NewLine, Environment.NewLine));
- // Displays the Logo commands:
- command.Dump();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement