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

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Prog: dragon.cpp // Draw turtle graphics for the Lindenmayer system with // productions X -> X+YF+, Y -> -FX-Y, initial word X // and rotation angle 90 degrees #include #include // necessary: x and y call each other void y (const unsigned int i); // POST: w_i^X is drawn void x (const unsigned int i) { if (i > 0) { x(i-1); // w_{i-1}^X ifm::left(90); // + y(i-1); // w_{i-1}^Y ifm::forward(); // F ifm::left(90); // + } } // POST: w_i^Y is drawn void y (const unsigned int i) { if (i > 0) { ifm::right(90); // - ifm::forward(); // F x(i-1); // w_{i-1}^X ifm::right(90); // - y(i-1); // w_{i-1}^Y } } int main () { std::cout << "Number of iterations =? "; unsigned int n; std::cin >> n; // draw w_n = w_n^X x(n); return 0; }