// As per the axiom and rules at https://www.youtube.com/watch?v=E1B4UoSQMFw
cleari()
setSpeed(superFast)
setBackground(cm.lightGrey)
zoom(0.35)
def steps = 5
val outputAfterGenerations = (0 until steps).foldLeft("F") { (generationOutput, _) =>
generationOutput.foldLeft("") { (previous, input) =>
val result = input match {
case 'F'=> "FF+[+F-F-F]-[-F+F+F]"
case _ => input.toString
}
previous + result
}
}
def tree = Picture {
setPenColor(cm.darkGreen)
def len = 10
def angle = 25
outputAfterGenerations.foreach {
case 'F' => forward(len)
case 'G' =>
penUp(); forward(len); penDown()
case '[' => savePosHe()
case ']' => restorePosHe()
case '+' => right(angle)
case '-' => left(angle)
case _ =>
}
}
drawCentered(tree)