我正在制作一个游戏,在这个游戏中,我需要显示穿越流动河流的船只。我正在用贝塞尔曲线创建河流,但它只有3个来自bezerCurveTo的控制点。因此,这条河不够"弯曲"我该如何实现这一目标?
烟草。GeometricMath类具有一些用于曲线、路径和合并数组的高级函数。为了实现你想要的,你可以将多条路径连接在一起。例如:https://codepen.io/Contrapenner/pen/mdBVrbw
function dot(x, y) {
var d = document.createElement("span");
d.setAttribute("style", "position:absolute;left:" + x + "px;top:" + y + "px;width:2px;height:2px;background: blue");
document.getElementById("river").appendChild(d);
};
var riverPath = tabageos.GeometricMath.getRawArcCurvePath(5, 5, 10, 10, 5, 15, 10);
riverPath = tabageos.GeometricMath.mergeArrays(riverPath, tabageos.GeometricMath.getRawArcCurvePath(5, 15, 0, 20, 5, 25, 10));
riverPath = tabageos.GeometricMath.mergeArrays(riverPath, tabageos.GeometricMath.getRawArcCurvePath(5, 25, 10, 30, 5, 35, 10));
riverPath = tabageos.GeometricMath.mergeArrays(riverPath, tabageos.GeometricMath.getRawArcCurvePath(5, 35, 0, 40, 5, 45, 10));
//and you could keep going as needed.
//there is also getRawHermiteCurvePath
var i = 0;
for (i; i < riverPath.length; i += 2) {
dot(riverPath[i], riverPath[i + 1]);
}