// Prog: HaringSarah.cpp
// Author: Sarah Haring
// Draws fractal tree - graphics for Lindenmeyer system
// Use 3 or 4 iterations for best results.
#include
#include
//#interations: i, angle: w
//POST: Draws tree with i iterations and uses w for angles
void f (const unsigned int i, const unsigned int w) {
if (i == 0)
ifm::forward(); // F
else {
f(i-1,w);
f(i-1,w);
ifm::right(w);
ifm::save(); //save current position
ifm::right(w);
f(i-1,w);
ifm::left(w);
f(i-1,w);
ifm::right(2*w);
f(i-1,w);
ifm::restore();// jump to last saved position
ifm::left(w);
ifm::save();
ifm::left(w);
f(i-1,w);
ifm::left(w);
f(i-1,w);
ifm::right(2*w);
f(i-1,w);
ifm::restore();
}
}
int main () {
//Input
std::cout << "Number of iterations =? ";
unsigned int n;
std::cin >> n;
//Output
ifm:: left(90);
ifm::forward(5*n); //"trunk"
ifm::save();
f(n,11); //tree1 angle 11
ifm::restore();
ifm::left(20);
ifm::save();
f(n,23);//tree2 angle 23
ifm::restore();
ifm::right(19);
f(n,30);//tree3 angle 30
return 0;
}