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

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Prog: DeBardeciFranco.cpp // Draw turtle graphics for the Lindenmayer system with // production F -> F+F+ and initial word F. #include #include // POST: the word w_i^F is drawn void f (const unsigned int i) { if (i == 0) ifm::forward(); // F else { ifm::forward(i*i*i); f(i-1); ifm :: save (); ifm :: left (60); f(i-1); ifm :: restore (); ifm :: save (); ifm :: left (10*(10-i)); f(i-1); ifm :: restore (); } } void g (const unsigned int i) { if (i == 0) ifm::forward(); // F else { ifm::forward(i*i*i); g(i-1); ifm :: save (); ifm :: right (60); g(i-1); ifm :: restore (); ifm :: save (); ifm :: right (10*(10-i)); g(i-1); ifm :: restore (); } } int main () { unsigned int n = 10; ifm::right (90); ifm::save(); // draw w_n = w_n(F) f(n); ifm::restore(); g(n); return 0; }