1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 22:28:16 +01:00
dotSCAD/examples/turtle/sierpinski_triangle.scad

39 lines
951 B
OpenSCAD
Raw Normal View History

2022-06-06 13:11:46 +08:00
use <polyline_join.scad>
use <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
2021-10-08 09:36:01 +08:00
polyline_join([for(turtle = [t, t2, t3, t]) t2d(turtle, "point")])
circle(thickness / 2);
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
}