2019-09-28 20:34:50 +08:00
|
|
|
include <hull_polyline2d.scad>;
|
2019-09-28 18:05:06 +08:00
|
|
|
include <turtle/t2d.scad>;
|
2019-07-29 20:46:06 +08:00
|
|
|
|
2019-09-28 18:05:06 +08:00
|
|
|
side_leng = 100;
|
|
|
|
min_leng = 4;
|
2019-09-28 09:58:34 +08:00
|
|
|
thickness = 0.5;
|
|
|
|
|
|
|
|
sierpinski_triangle(
|
2019-09-28 18:05:06 +08:00
|
|
|
t2d(point = [0, 0], angle = 0),
|
2019-09-28 20:34:50 +08:00
|
|
|
side_leng, min_leng, thickness, $fn = 3
|
2019-09-28 09:58:34 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
module triangle(t, side_leng, thickness) {
|
2019-09-28 18:05:06 +08:00
|
|
|
t2 = t2d(t, "forward", leng = side_leng);
|
2019-09-28 18:11:15 +08:00
|
|
|
t3 = t2d(t2, [
|
2019-09-28 18:05:06 +08:00
|
|
|
["turn", 120],
|
|
|
|
["forward", side_leng]
|
|
|
|
]);
|
2019-09-28 09:58:34 +08:00
|
|
|
|
2019-09-28 20:34:50 +08:00
|
|
|
hull_polyline2d(
|
2019-09-28 20:36:17 +08:00
|
|
|
[for(turtle = [t, t2, t3, t]) t2d(turtle, "point")],
|
2019-09-28 20:34:50 +08:00
|
|
|
thickness
|
|
|
|
);
|
2019-07-29 20:46:06 +08:00
|
|
|
}
|
|
|
|
|
2019-09-28 18:05:06 +08:00
|
|
|
module sierpinski_triangle(t, side_leng, min_leng, thickness) {
|
|
|
|
triangle(t, side_leng, thickness);
|
2019-09-28 09:58:34 +08:00
|
|
|
|
2019-09-28 18:05:06 +08:00
|
|
|
if(side_leng >= min_leng) {
|
|
|
|
half_leng = side_leng / 2;
|
|
|
|
t2 = t2d(t, "forward", leng = half_leng);
|
2019-09-28 18:11:15 +08:00
|
|
|
t3 = t2d(t, [
|
2019-09-28 18:05:06 +08:00
|
|
|
["turn", 60],
|
|
|
|
["forward", half_leng],
|
|
|
|
["turn", -60]
|
|
|
|
]);
|
2019-09-28 09:58:34 +08:00
|
|
|
for(turtle = [t, t2, t3]) {
|
2019-09-28 18:05:06 +08:00
|
|
|
sierpinski_triangle(turtle, half_leng, min_leng, thickness);
|
2019-09-28 09:58:34 +08:00
|
|
|
}
|
2019-07-29 20:46:06 +08:00
|
|
|
}
|
2019-09-28 09:58:34 +08:00
|
|
|
}
|