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

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Informatik - Serie 11 - Lindenmayer Challenge // Programm: ReitmannRafael.cpp // Draw turtle graphics for the Lindenmayer system // Autor: Rafael Rietmann #include #include // POST: the word w_i^F is drawn void e (const unsigned int i) { if (i == 0){ ifm::forward(); } else { ifm::forward(); e(i-1); ifm::left(90); e(i-1); e(i-1); ifm::left(90); e(i-1); ifm::right(90); e(i-1); e(i-1); ifm::right(90); e(i-1); e(i-1); ifm::right(90); e(i-1); e(i-1); ifm::right(90); e(i-1); ifm::left(90); e(i-1); e(i-1); ifm::left(90); e(i-1); ifm::forward(); } } void g (const unsigned int i) { if (i == 0){ ifm::forward(); } else { ifm::right(180); g(i-1); ifm::right(20); g(i-1); ifm::right(180); g(i-1); ifm::right(150); g(i-1); ifm::right(10); g(i-1); } } 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(); // ] } } void y (const unsigned int i) { if (i == 0) ifm::forward(); // F else { y(i-1); // w_{i-1}^F y(i-1); // w_{i-1}^F ifm::left(5); // - ifm::save(); // [ stores current position and direction ifm::left(23); // - y(i-1); // w_{i-1}^F ifm::left(23); // + y(i-1); // w_{i-1}^F ifm::right(23); // + y(i-1); // w_{i-1}^F ifm::restore(); // ] goes back to last stored position / direction ifm::right(23); // + ifm::save(); // [ ifm::right(23); // + y(i-1); // w_{i-1}^F ifm::right(23); // - y(i-1); // w_{i-1}^F ifm::save(); ifm::left(23); // - y(i-1); // w_{i-1}^F ifm::restore(); ifm::left(60); // - y(i-1); ifm::restore(); // ] } } void b (const unsigned int i) { if (i == 0) ifm::forward(); // F else { ifm::right(20); b(i-1); ifm::left(50); b(i-1); ifm::left(210); b(i-1); ifm::left(50); b(i-1); // ifm::forward(); } } int main () { std::cout << "Number of iterations =? "; unsigned int n; std::cin >> n; //g(n); //y(n); e(n); //f(n); // b(n); return 0; }