简体   繁体   中英

Ways to make bezier curves with about 8-9 control points in Javascript

I am making a game where i need to display ship traversing a flowing river. I am creating river with bezier curves but it is with only 3 control points from the bezerCurveTo . So, the river is not 'curvy enough.' How can i go about achieving this?

The tabageos.GeometricMath Class has some advanced functions for curves, paths and merging Arrays. To accomplish what you want you could join multiple paths together. For example: 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]);
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM