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

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Prog: bush.cpp // Draw turtle graphics for the Lindenmayer system with // production F -> FF-[-F+F+F]+[+F-F-F], initial word F and // rotation angle 23 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 f(i-1); // w_{i-1}^F ifm::left(23); // - ifm::save(); // [ stores current position and direction ifm::left(23); // - f(i-1); // w_{i-1}^F ifm::right(23); // + f(i-1); // w_{i-1}^F ifm::right(23); // + f(i-1); // w_{i-1}^F ifm::restore(); // ] goes back to last stored position / direction ifm::right(23); // + ifm::save(); // [ ifm::right(23); // + f(i-1); // w_{i-1}^F ifm::left(23); // - f(i-1); // w_{i-1}^F ifm::left(23); // - f(i-1); // w_{i-1}^F ifm::restore(); // ] } } int main () { std::cout << "Number of iterations =? "; unsigned int n; std::cin >> n; // draw w_n = w_n^F ifm::left(90); // loook up f(n); // w_n^F return 0; }