mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-11 09:14:29 +02:00
update
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 27 KiB |
Binary file not shown.
Before Width: | Height: | Size: 57 KiB |
Binary file not shown.
Before Width: | Height: | Size: 12 KiB |
Binary file not shown.
Before Width: | Height: | Size: 62 KiB |
@@ -1,88 +0,0 @@
|
|||||||
# turtle2d
|
|
||||||
|
|
||||||
The dir changed since 2.0.
|
|
||||||
|
|
||||||
An OpenSCAD implementation of Turtle Graphics. It moves on the xy plane. You can get the cooridinate `[x, y]` or `angle` of its current position.
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `cmd` : A string command. Different commands use different numbers of arguments.
|
|
||||||
- `"create"` : Creates a turtle data. The command needs three arguments `x`, `y` and `angle`. For example, use `turtle2d("create", 5, 10, 30)` to create a turtle located at `[5, 10]` with an angle `30` degrees.
|
|
||||||
- `"x"` : Sets or gets the `x` coordinate of a turtle. If you provide a turtle data and the `x` coordinate, such as `turtle2d("x", turtle, 20)`, it will sets the `x` coordinate. Giving a turtle data only will return the `x` coordinate.
|
|
||||||
- `"y"` : Sets or gets the `y` coordinate of a turtle. If you provide a turtle data and the `y` coordinate, such as `turtle2d("y", turtle, 20)`, it will sets the `y` coordinate. Giving a turtle data only will return the `y` coordinate.
|
|
||||||
- `"angle"` : Sets or gets the angle of a turtle. If you provide a turtle data and the angle, such as `turtle2d("angle", turtle, 45)`, it will sets the angle. Giving a turtle data only will return the angle.
|
|
||||||
- `"pt"` : Sets or Gets `[x, y]` of a turtle. If you provide a turtle data and the coordinates, such as `turtle2d("pt", turtle, [10, 20])`, it will sets the coordinates. Giving a turtle data only will return the coordinates.
|
|
||||||
- `"forward"` : Forwards a turtle. The command needs two arguments. The first one is a turtle data, and the second one is the length. For example, `turtle2d("forward", turtle, 100)`.
|
|
||||||
- `"turn"` : Turns a turtle. The command needs two arguments. The first one is a turtle data, and the second one is the angle. For example, `turtle2d("turn", turtle, 180)`.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
use <line2d.scad>;
|
|
||||||
use <turtle/turtle2d.scad>;
|
|
||||||
|
|
||||||
module turtle_spiral(t_before, times, side_leng, angle, width) {
|
|
||||||
$fn = 24;
|
|
||||||
if(times != 0) {
|
|
||||||
t_after_tr = turtle2d("turn", t_before, angle);
|
|
||||||
t_after_fd = turtle2d("forward", t_after_tr, side_leng);
|
|
||||||
|
|
||||||
line2d(
|
|
||||||
turtle2d("pt", t_before),
|
|
||||||
turtle2d("pt", t_after_fd),
|
|
||||||
width,
|
|
||||||
p1Style = "CAP_ROUND",
|
|
||||||
p2Style = "CAP_ROUND"
|
|
||||||
);
|
|
||||||
|
|
||||||
turtle_spiral(t_after_fd, times - 1, side_leng, angle, width);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
side_leng = 10;
|
|
||||||
angle = 144;
|
|
||||||
width = 1;
|
|
||||||
times = 5;
|
|
||||||
|
|
||||||
turtle_spiral(turtle2d("create", 0, 0, 0), times, side_leng, angle, width);
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
use <line2d.scad>;
|
|
||||||
use <turtle/turtle2d.scad>;
|
|
||||||
|
|
||||||
module turtle_spiral(t_before, side_leng, d_step, min_leng, angle, width) {
|
|
||||||
$fn = 24;
|
|
||||||
if(side_leng > min_leng) {
|
|
||||||
t_after = turtle2d("forward", turtle2d("turn", t_before, angle), side_leng);
|
|
||||||
|
|
||||||
line2d(
|
|
||||||
turtle2d("pt", t_before),
|
|
||||||
turtle2d("pt", t_after),
|
|
||||||
width,
|
|
||||||
p1Style = "CAP_ROUND",
|
|
||||||
p2Style = "CAP_ROUND"
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
turtle_spiral(t_after, side_leng - d_step, d_step, min_leng, angle, width);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
side_leng = 50;
|
|
||||||
d_step = 1;
|
|
||||||
min_leng = 1;
|
|
||||||
angle = 90;
|
|
||||||
width = 1;
|
|
||||||
|
|
||||||
turtle_spiral(
|
|
||||||
turtle2d("create", 0, 0, 0),
|
|
||||||
side_leng,
|
|
||||||
d_step,
|
|
||||||
min_leng,
|
|
||||||
angle,
|
|
||||||
width
|
|
||||||
);
|
|
||||||
|
|
||||||

|
|
@@ -1,89 +0,0 @@
|
|||||||
# turtle3d
|
|
||||||
|
|
||||||
The dir changed since 2.0.
|
|
||||||
|
|
||||||
An OpenSCAD implementation of 3D Turtle Graphics. When using the function, imagine that you are sitting on the turtle. You move or turn the turtle from the your viewpoint, not the viewpoint of OpenSCAD coordinates.
|
|
||||||
|
|
||||||
For more details, please see [3D turtle graphics](https://openhome.cc/eGossip/OpenSCAD/3DTurtleGraphics.html).
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
- `cmd` : A string command. Different commands use different numbers of arguments.
|
|
||||||
- `"create"` : Creates a turtle data. The simplest way is `turtle3d("create")` which creates a turtle located at `[0, 0, 0]` (and unit vectors `[[1, 0, 0], [0, 1, 0], [0, 0, 1]]`). You can pass your own starting point and unit vectors, such as `turtle3d("create", [0, 0, 0], [[1, 0, 0], [0, 1, 0], [0, 0, 1]])`.
|
|
||||||
- `"xu_move"`, `"yu_move"`, `"zu_move"` : These commands need two arguments, the turtle data and the length you want to move from your viewpoint (you sit on the turtle). For example, `"turtle3d("xu_move", turtle, 10)"`.
|
|
||||||
- `"xu_turn"`, `"yu_turn"`, `"zu_turn"` : These commands need two arguments, the turtle data and the angle you want to turn from your viewpoint (you sit on the turtle). For example, `"turtle3d("xu_turn", turtle, 45)"`.
|
|
||||||
- `"pt"` : Gets the point of the turtle. It requires one argument, the turtle data. For example, `"turtle3d("pt", turtle)"`.
|
|
||||||
- `"unit_vts"` : Gets the unit vectors of the turtle. It requires one argument, the turtle data. For example, `"turtle3d("unit_vts", turtle)"`.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
use <turtle/turtle3d.scad>;
|
|
||||||
use <hull_polyline3d.scad>;
|
|
||||||
|
|
||||||
leng = 10;
|
|
||||||
angle = 120;
|
|
||||||
thickness = 1;
|
|
||||||
|
|
||||||
t = turtle3d("create");
|
|
||||||
|
|
||||||
t2 = turtle3d("xu_move", t, leng);
|
|
||||||
hull_polyline3d(
|
|
||||||
[turtle3d("pt", t), turtle3d("pt", t2)],
|
|
||||||
thickness
|
|
||||||
);
|
|
||||||
|
|
||||||
t3 = turtle3d("xu_move", turtle3d("zu_turn", t2, angle), leng);
|
|
||||||
hull_polyline3d(
|
|
||||||
[turtle3d("pt", t2), turtle3d("pt", t3)],
|
|
||||||
thickness
|
|
||||||
);
|
|
||||||
|
|
||||||
t4 = turtle3d("xu_move", turtle3d("zu_turn", t3, angle), leng);
|
|
||||||
hull_polyline3d(
|
|
||||||
[turtle3d("pt", t3), turtle3d("pt", t4)],
|
|
||||||
thickness
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
use <turtle/turtle3d.scad>;
|
|
||||||
use <hull_polyline3d.scad>;
|
|
||||||
|
|
||||||
module tree(t, leng, leng_scale1, leng_scale2, leng_limit,
|
|
||||||
angleZ, angleX, width) {
|
|
||||||
if(leng > leng_limit) {
|
|
||||||
t2 = turtle3d("xu_move", t, leng);
|
|
||||||
|
|
||||||
hull_polyline3d(
|
|
||||||
[turtle3d("pt", t), turtle3d("pt", t2)],
|
|
||||||
width);
|
|
||||||
|
|
||||||
tree(
|
|
||||||
turtle3d("zu_turn", t2, angleZ),
|
|
||||||
leng * leng_scale1, leng_scale1, leng_scale2, leng_limit,
|
|
||||||
angleZ, angleX,
|
|
||||||
width);
|
|
||||||
|
|
||||||
tree(
|
|
||||||
turtle3d("xu_turn", t2, angleX),
|
|
||||||
leng * leng_scale2, leng_scale1, leng_scale2, leng_limit,
|
|
||||||
angleZ, angleX,
|
|
||||||
width);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
leng = 100;
|
|
||||||
leng_limit = 1;
|
|
||||||
leng_scale1 = 0.4;
|
|
||||||
leng_scale2 = 0.9;
|
|
||||||
angleZ = 60;
|
|
||||||
angleX = 135;
|
|
||||||
width = 2;
|
|
||||||
|
|
||||||
t = turtle3d("create");
|
|
||||||
|
|
||||||
tree(t, leng, leng_scale1, leng_scale2, leng_limit,
|
|
||||||
angleZ, angleX, width);
|
|
||||||
|
|
||||||

|
|
@@ -31,3 +31,4 @@ New modules/functions
|
|||||||
|
|
||||||
- delete `m_cumulate`
|
- delete `m_cumulate`
|
||||||
- delete `trianglate`, use `tri_ear_clipping`?
|
- delete `trianglate`, use `tri_ear_clipping`?
|
||||||
|
- `turtle/turtle2d` and `turtle/turtle3d` used internally.
|
Reference in New Issue
Block a user