// Prog: dragon.cpp
// Draw turtle graphics for the Lindenmayer system with
// productions X -> X+YF+, Y -> -FX-Y, initial word X
// and rotation angle 90 degrees
#include
#include
// necessary: x and y call each other
void y (const unsigned int i);
void h(const unsigned int i);
// POST: w_i^X is drawn
void x (const unsigned int i) {
if (i > 0) {
x(i-1); // w_{i-1}^X
// y(i-1);
ifm::left(90); //
// y(i-1); // w_{i-1}^Y
// ifm::forward(); // F
h(i-1);
ifm::left(90); // +
}
}
// POST: w_i^Y is drawn
void y (const unsigned int i) {
if (i > 0) {
ifm::right(90); // -
// ifm::forward(); // F
x(i-1); // w_{i-1}^X
ifm::right(90); // -
}
}
void h (const unsigned int i){
if(i>0){
ifm::left(90);
x(i-1);
y(i-1);
//ifm::forward();
ifm::right(90);
ifm::forward();
ifm::forward();
}
}
int main () {
std::cout << "Number of iterations =? ";
unsigned int n;
std::cin >> n;
// draw w_n = w_n^X
x(n);
return 0;
}