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 - Aufgabe 107 // Program: PuravPanchal.C // zeichnet Lindenmayer system // Autor: Purav Panchal (Gruppe D) //Pre: n number of recursions //Post: word from the Lindenmayer system is drawn #include #include void Y(unsigned int n); void X(unsigned int n) { if (n == 0) { ifm::forward(); } else { X(n-1); ifm::save(); ifm::left(50); X(n-1); ifm::restore(); ifm::save(); ifm::right(50); X(n-1); ifm::restore(); ifm::save(); X(n-1); ifm::restore(); } } void Y(unsigned int n) { if (n == 0) { ifm::forward(); } else { Y(n-1); ifm::save(); ifm::left(35); Y(n-1); ifm::restore(); ifm::save(); ifm::right(40); Y(n-1); ifm::restore(); ifm::save(); Y(n-1); ifm::restore(); } } void Z(unsigned int n) { if (n == 0) { ifm::forward(); } else { Z(n-1); ifm::save(); ifm::left(45); Z(n-1); Z(n-1); ifm::restore(); ifm::save(); ifm::right(15); Z(n-1); ifm::restore(); ifm::save(); Z(n-1); ifm::restore(); } } int main() { //Number of recursions unsigned int n; std::cout << "How many recursions do you want to be drawn?" << std::endl; std::cin >> n; ifm::save(); ifm::forward(n); X(n); ifm::restore(); ifm::save(); ifm::left(75); ifm::forward(); ifm::right(10); ifm::forward(); ifm::right(10); Y(n); ifm::restore(); ifm::save(); ifm::right(90); ifm::forward(); ifm::left(5); ifm::forward(); ifm::left(10); Z(n); ifm::restore(); return 0; }