2019-07-29 20:46:06 +08:00
|
|
|
include <line2d.scad>;
|
2019-09-28 09:58:34 +08:00
|
|
|
include <polyline2d.scad>;
|
2019-07-29 20:46:06 +08:00
|
|
|
include <turtle/turtle2d.scad>;
|
|
|
|
|
2019-09-28 09:58:34 +08:00
|
|
|
side_len = 100;
|
|
|
|
min_len = 4;
|
|
|
|
thickness = 0.5;
|
|
|
|
|
|
|
|
sierpinski_triangle(
|
|
|
|
turtle2d("create", 0, 0, 0),
|
|
|
|
side_len, min_len, thickness, $fn = 12
|
|
|
|
);
|
|
|
|
|
|
|
|
module triangle(t, side_leng, thickness) {
|
|
|
|
t2 = turtle2d("forward", t, side_leng);
|
|
|
|
t3 = turtle2d("forward", turtle2d("turn", t2, 120), side_leng);
|
|
|
|
|
|
|
|
polyline2d([
|
|
|
|
turtle2d("pt", t),
|
|
|
|
turtle2d("pt", t2),
|
|
|
|
turtle2d("pt", t3),
|
|
|
|
turtle2d("pt", t)
|
|
|
|
], thickness, startingStyle = "CAP_ROUND", endingStyle = "CAP_ROUND");
|
2019-07-29 20:46:06 +08:00
|
|
|
}
|
|
|
|
|
2019-09-28 09:58:34 +08:00
|
|
|
module sierpinski_triangle(t, side_len, min_len, thickness) {
|
|
|
|
triangle(t, side_len, thickness);
|
|
|
|
|
2019-09-28 11:36:57 +08:00
|
|
|
if(side_len >= min_len) {
|
2019-09-28 09:58:34 +08:00
|
|
|
half_len = side_len / 2;
|
|
|
|
t2 = turtle2d("forward", t, half_len);
|
|
|
|
t3 = turtle2d("turn", turtle2d("forward", turtle2d("turn", t, 60), half_len), -60);
|
|
|
|
for(turtle = [t, t2, t3]) {
|
|
|
|
sierpinski_triangle(turtle, half_len, min_len, thickness);
|
|
|
|
}
|
2019-07-29 20:46:06 +08:00
|
|
|
}
|
2019-09-28 09:58:34 +08:00
|
|
|
}
|