Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. // Start:
  2. string koch = "F";
  3.  
  4. // Rule: F -> F+F-F-F+F
  5. Func<string, string> transform = x => x.Replace("F", "F+F-F-F+F");
  6.  
  7. // Fractal length:
  8. int length = 3;
  9.  
  10. // Intialize the location and direction of the turtle:
  11. string command = @"home
  12. setxy 10 340
  13. right 90
  14. ";
  15.  
  16. // Recursive definition to generate Logo commands:
  17. command += Enumerable.Range(1, length)
  18. .Select(k => koch = transform(koch))
  19. .Last()
  20. .Replace("F", "forward 15")
  21. .Replace("+", String.Format("{0}Left 90{1}", Environment.NewLine, Environment.NewLine))
  22. .Replace("-", String.Format("{0}Right 90{1}", Environment.NewLine, Environment.NewLine));
  23.  
  24. // Displays the Logo commands:
  25. command.Dump();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement