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 - Skriptaufgabe 125 // Program: WehnerDavid.cpp // Autor: David Wehner // Iterations: 5 // Draw a fruit-bearing tree (the two functions are taken from the programs of last year // written by Quintin Meier and Patrick Pietsch. #include #include #include #include using namespace std; using namespace ifm; void f (unsigned int i) // "fruit" { if (i == 0) ifm::forward(); // F else { f(i-1); // w_{i-1}^F ifm::left(40); ifm::forward(); ifm::right(10); // + f(i-1); // w_{i-1}^F ifm::right(20); // + } } void w (int n)//branch grows; its length being determined by its position { forward (50*n+100); if (n==0) f(8); } void k (int n)//new branches; angles determined at random { if (n!=0) { save(); left(rand()%81-40); w(n-1); save(); left(rand()%81-40); w(n-1); k(n-1); restore(); k(n-1); restore(); if (rand()%2==0) { save(); right(rand()%81-40); w(n-1); k(n-1); restore(); } right(rand()%81-40); w(n-1); save(); k(n-1); restore(); left(rand()%81-40); w(n-1); k(n-1); } } int main()//main function { int n; cout<<"This program draws a fruit-bearing tree.\n" << "Please enter the number of iterations (5 would be quite a good idea):\n"; cin >> n; left (90); w(n); k(n); return 0; }