Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Sierpinski {
- public:
- void curve( int order, double length, int angle)
- {
- if ( 0 == order ) {
- cout << length << " " << length << " rlineto" << endl;
- } else {
- curve(order - 1, length / 2, - angle);
- cout <<angle << " rotate" << endl;
- curve( order - 1, length / 2, + angle);
- cout << angle <<" rotate"<<endl;
- curve( order - 1, length / 2, - angle);
- }
- }
- void sierpinski_arrowhead_curve( int order, double length)
- {
- // If order is even we can just draw the curve.
- if ( 0 == (order & 1) ) {
- cout << "60 rotate"<<endl;
- curve( order, length, +60);
- }
- else /* order is odd */ {
- cout << "60 rotate"<<endl;
- curve( order, length, -60);
- }
- }
- void draw(int order, double length) {
- cout << "newpath" << endl;
- cout << "100 200 moveto" << endl;
- sierpinski_arrowhead_curve(order, length);
- cout << "stroke" << endl;
- }
- };
- int main(void) {
- Sierpinski s;
- s.draw(2 ,100);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement