Advertisement
Fhernd

VT2.12-Comandos-Logo-Triángulo-Sierpinski.linq

Jan 28th, 2017
38,832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. // Axioma:
  2. string trianguloSierpinski = "A";
  3.  
  4. // Reglas de producción:
  5. Func<string, string> transformarA = x => x.Replace("A", "B-A-B");
  6. Func<string, string> marcarBs = x => x.Replace("B", "[B]");
  7. Func<string, string> transformarB = x => x.Replace("[B]", "A+B+A");
  8.  
  9. // Nivel de recursión:
  10. int nivelRecursion = 6;
  11.  
  12. Enumerable.Range(1, nivelRecursion)
  13.     .ToList()
  14.     .ForEach(
  15.         numRecursion =>
  16.         {
  17.             trianguloSierpinski = transformarB(transformarA(marcarBs(trianguloSierpinski)));
  18.         }
  19.     );
  20.    
  21. trianguloSierpinski
  22.     .Replace("A", "forward 5" + Environment.NewLine)
  23.     .Replace("B", "forward 5" + Environment.NewLine)
  24.     .Replace("+", "left 60" + Environment.NewLine)
  25.     .Replace("-", "right 60" + Environment.NewLine)
  26.     .Dump("Comandos Logo para Triángulo de Sierpinski");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement