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

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Prog: EndressLara.cpp // Draw turtle graphics for the Lindenmayer system with // productions X -> X+YF+, Y -> -FX-Y, initial word X // Lara Endress #include #include // necessary: x and y call each other void y (const unsigned int i); void z (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(i+45); ifm::forward(); // + y(i-1); // w_{i-1}^Y ifm::forward(); // F ifm::right(i+90); // + ifm::forward(); } } void z (const unsigned int i) { if (i > 0) { ifm::forward(); ifm::right(60); // - ifm::forward(); // F x(i-1); // w_{i-1}^X ifm::left(90); // - y(i-1); ifm::forward();// w_{i-1}^Y } } // POST: w_i^Y is drawn void y (const unsigned int i) { if (i > 0) { ifm::forward(); ifm::right(i+30); // - ifm::forward(); // F x(i-1); // w_{i-1}^X ifm::left(i+60); // - z(i-1); ifm::forward();// 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; }