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

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Prog:HadornStefan // Title: coffeebeans // Author: S.Hadorn Group N // Informatics: Series 11 Challenge Task // Draw turtle graphics for the Lindenmayer system with // production F -> F-F--F---, initial word F+F+F+F+F+F and // rotation angle + == 30 degrees, - == 45 degrees. #include #include // POST: the word w_i^F is drawn void f (const unsigned int i) { if (i == 0) ifm::forward(); // F else { f(i-1); // w_{i-1}^F ifm::right(45); // - ifm::forward(); f(i-1); // w_{i-1}^F ifm::left(90); // -- ifm::save(); // save point f(i-1); // w_{i-1}^F ifm::restore(); // jump back ifm::right(135); // --- } } int main () { std::cout << "Number of iterations =? "; unsigned int n; std::cin >> n; // draw w_n = w_n^F + w_n^F + w_n^F + w_n^F + w_n^F + w_n^F f(n); // w_n^F ifm::right(30); // + f(n); // w_n^F ifm::right(30); // + f(n); // w_n^F ifm::right(30); // + f(n); // w_n^F ifm::right(30); // + f(n); // w_n^F ifm::right(30); // + f(n); // w_n^F return 0; }