Sierpinski curve: Difference between revisions
Content added Content deleted
m (Refactored C++ code) |
m (C++ - calculate initial x and y from length) |
||
Line 175: | Line 175: | ||
class sierpinski_curve { |
class sierpinski_curve { |
||
public: |
public: |
||
void write(std::ostream& out, int size, |
void write(std::ostream& out, int size, int length, int order); |
||
int length, int order); |
|||
private: |
private: |
||
static std::string rewrite(const std::string& s); |
static std::string rewrite(const std::string& s); |
||
Line 187: | Line 186: | ||
}; |
}; |
||
void sierpinski_curve::write(std::ostream& out, int size, |
void sierpinski_curve::write(std::ostream& out, int size, int length, int order) { |
||
int length, int order) { |
|||
length_ = length; |
length_ = length; |
||
x_ = |
x_ = length/std::sqrt(2.0); |
||
y_ = |
y_ = 2 * x_; |
||
angle_ = 45; |
angle_ = 45; |
||
out << "<svg xmlns='http://www.w3.org/2000/svg' width='" |
out << "<svg xmlns='http://www.w3.org/2000/svg' width='" |
||
Line 247: | Line 245: | ||
} |
} |
||
sierpinski_curve s; |
sierpinski_curve s; |
||
s.write(out, 545 |
s.write(out, 545, 7, 5); |
||
return 0; |
return 0; |
||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |
||
See: [https://slack-files.com/T0CNUL56D- |
See: [https://slack-files.com/T0CNUL56D-F01GZ1BU4RZ-99f34b7076 sierpinski_curve.svg] (offsite SVG image) |
||
=={{header|Factor}}== |
=={{header|Factor}}== |