# Variant of the Sierpinski curves in C++; help

1. May 15, 2012

### John O' Meara

Code (Text):

using namespace std;

enum direction {north, east, south, west };

direction right(direction d)
{ // return the direction to the right (clockwise)
switch(d) {
case north:  return east;
case east:   return south;
case south: return west;
case west:  return north;
}
}

ostream& operator<<(ostream& c, direction d)
{ // write a direction
switch(d) {
case north:   c << "north"; break;
case east:     c << " east"; break;
case south:   c << "south"; break;
case west:    c << " west"; break;
}
}

void edge(direction d, int i);
direction left(direction d);

void Sierpinski(int i)
{ // Draw Sierpinski curve of order i
direction d = north;
do {
edge(d, i);
d = right(d);
}while(d != north);
}

direction left(direction d, int i)
{ // Return direction to the left (counterclockwise)
switch(d) {
case north:    return west;
case east:     return north;
case south:   return east;
case west:    return south;
}
}

void edge(direction d, int i)
{
if(i == -1)
cout << d << " 2 cm\n";
else {
edge(left(d), i-1);
edge(d, i-1);
edge(right(d), i-1);
}
}

int main()
{
Sierpinski(1);

return 0;
}
The question is question 3 in the attachment. The program above for a first order curve Sierpinski(1); it "draws" a zero order curve and then overwirtes that cross shape three times. I cannot get it to draw the first order or higher order curves. Because the only other symmetry I can see in the zero order curve is central symmetry in the center of the cross. I don't know how to break the zero order curve down to simplier components, than north, south, east and west directions? Looking at the attachment is the only way you are going to know what I am talking about, there are drawings of zero, first, second and third order curves. Thanks for the help in advance.

File size:
1.4 MB
Views:
66