Department of Computer Science | Institute of Theoretical Computer Science | CADMO

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Informatik - Serie 11 - Challenge Aufgabe 127 // Programm: RossinelliGiulia.cpp // Autor: G.Rossinelli // Draw turtle graphics for the Lindenmayer system with // production F -> FF[-F-F-F][+FF+F+]F , initial word F and // rotation angle 42 degrees. #include #include // POST: the word w_i^F is drawn void f (const unsigned int i) { if (i == 0) ifm::forward(); // F else { f(i-1); // w_{i-1}^F ifm::forward(); // F ifm::save(); // [ stores current position and direction ifm::right(42); // - ifm::forward(); // F ifm::right(42); // - ifm::forward(); // F ifm::right(42); // - f(i-1); // w_{i-1}^F ifm::restore(); // ] goes back to last stored position and direction ifm::save(); // [ stores current position and direction ifm::left(42); // + f(i-1); // w_{i-1}^F ifm::forward(); // F ifm::left(42); // + ifm::forward(); // F ifm::left(42); // + ifm::restore(); // ] goes back to last stored position and direction f(i-1); // w_{i-1}^F } } int main () { std::cout << "Number of iterations =? "; unsigned int n; std::cin >> n; // draw w_n = w_n^F ifm::left(42); // + f(n); // w_n^F return 0; }