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

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Prog: bush.C // Draw turtle graphics for the Lindenmayer system with // production F -> FF+[+F-F-F]-[-F+F+F], initial word F // and rotation angle 22 degrees #include #include // POST: the word w_i^F is drawn void f (unsigned int i) { if (i == 0) ifm::forward(); // F else { f(i-1); // F f(i-1); // F ifm::left(22); // + ifm::save(); // [ ifm::left(22); // + f(i-1); // F ifm::right(22); // - f(i-1); // F ifm::right(22); // - f(i-1); // F ifm::restore(); // ] ifm::right(22); // - ifm::save(); // [ ifm::right(22); // - f(i-1); // F ifm::left(22); // + f(i-1); // F ifm::left(22); // + f(i-1); // F ifm::restore(); // ] } } int main () { std::cout << "Number of iterations =? "; unsigned int n; std::cin >> n; // draw w_n = w_n(F), vertically ifm::left(90); f(n); return 0; }