// Progam: my_turtle.cpp
// from Sandra Buob
// use 5 as number of iterations
// Draw turtle graphics for the Lindenmayer system with
// productions X -> Y+X+ , Y -> XXXXX-YYYYY- , initial word Y
// and rotation angle 60 degrees, X=1stepforward=Y
#include
#include
// necessary: x and y call each other
void x (const unsigned int i);
// POST: w_i^Y is drawn
void y (const unsigned int i) {
if (i > 0) { // Y -> XXXXX- YYYYY-
x(i-1);
ifm::forward(); // X
x(i-1);
ifm::forward(); // X
x(i-1);
ifm::forward(); // X
x(i-1);
ifm::forward(); // X
x(i-1);
ifm::forward(); // X
ifm::right(60); // -
y(i-1);
ifm::forward(); // Y
y(i-1);
ifm::forward(); // Y
y(i-1);
ifm::forward(); // Y
y(i-1);
ifm::forward(); // Y
y(i-1);
ifm::forward(); // Y
ifm::right(60); // -
}
}
// POST: w_i^Y is drawn
void x (const unsigned int i) {
if (i > 0) { // X -> Y+X+
y(i-1);
ifm::forward(); // Y
ifm::left(60); // +
x(i-1);
ifm::forward(); // X
ifm::left(60); // +
}
}
int main () {
std::cout << "Number of iterations =? ";
unsigned int n;
std::cin >> n;
// draw w_n = w_n^Y
y(n);
return 0;
}