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 - Aufgabe 125 // Programm: CorrodiSimon.cpp // Autor: Simon Corrodi // Draw turtle graphics for the Lindenmayer system with // production F -> F+F+ and initial word F. // 3 Iterationen: Advent, Advent,... =) #include #include void p (const unsigned int i) { const int w = 13; if(i==0) ifm::forward(); else{ p(i-1); p(i-1); ifm::left(w); ifm::save(); ifm::left(w); p(i-1); ifm::right(w); p(i-1); ifm::right(w); p(i-1); ifm::right(w); ifm::restore(); ifm::right(w); ifm::save(); ifm::right(w); p(i-1); ifm::left(w); p(i-1); ifm::left(w); p(i-1); ifm::restore(); } } // POST: the word w_i^F is drawn void f (const unsigned int i) { if (i == 0) ifm::forward(); else { ifm::save(); f(i-1); f(i-1); ifm::left(18); ifm::save(); ifm::left(18); f(i-1); ifm::right(18); f(i-1); ifm::right(18); f(i-1); ifm::right(18); ifm::restore(); ifm::right(18); ifm::save(); ifm::right(18); f(i-1); ifm::left(18); f(i-1); ifm::left(18); f(i-1); ifm::restore(); ifm::restore(); ifm::left(18); ifm::left(18); ifm::left(18); ifm::save(); f(i-1); f(i-1); ifm::left(18); ifm::save(); ifm::left(18); f(i-1); ifm::right(18); f(i-1); ifm::right(18); f(i-1); ifm::right(18); ifm::restore(); ifm::right(18); ifm::save(); ifm::right(18); f(i-1); ifm::left(18); f(i-1); ifm::left(18); f(i-1); ifm::restore(); ifm::restore(); } } int main () { std::cout << "Number of iterations =? "; unsigned int n; std::cin >> n; f(n); ifm::left(112); p(n); return 0; }