课程表

微信小程序框架

微信小程序组件

微信小程序API

微信小程序开放接口

微信小程序工具

微信小程序设计规范

工具箱
速查手册

小程序API 三次方贝塞尔曲线

当前位置:免费教程 » 移动开发 » 微信小程序

微信小程序 canvas接口和方法绘图接口和方法

bezierCurveTo


定义

创建三次方贝塞尔曲线路径。

Tip: 曲线的起始点为路径中前一个点。

参数

参数类型说明
cp1xNumber第一个贝塞尔控制点的 x 坐标
cp1yNumber第一个贝塞尔控制点的 y 坐标
cp2xNumber第二个贝塞尔控制点的 x 坐标
cp2yNumber第二个贝塞尔控制点的 y 坐标
xNumber结束点的 x 坐标
yNumber结束点的 y 坐标

例子

  1. const ctx = wx.createCanvasContext('myCanvas')
  2. // Draw points
  3. ctx.beginPath()
  4. ctx.arc(20, 20, 2, 0, 2 * Math.PI)
  5. ctx.setFillStyle('red')
  6. ctx.fill()
  7. ctx.beginPath()
  8. ctx.arc(200, 20, 2, 0, 2 * Math.PI)
  9. ctx.setFillStyle('lightgreen')
  10. ctx.fill()
  11. ctx.beginPath()
  12. ctx.arc(20, 100, 2, 0, 2 * Math.PI)
  13. ctx.arc(200, 100, 2, 0, 2 * Math.PI)
  14. ctx.setFillStyle('blue')
  15. ctx.fill()
  16. ctx.setFillStyle('black')
  17. ctx.setFontSize(12)
  18. // Draw guides
  19. ctx.beginPath()
  20. ctx.moveTo(20, 20)
  21. ctx.lineTo(20, 100)
  22. ctx.lineTo(150, 75)
  23. ctx.moveTo(200, 20)
  24. ctx.lineTo(200, 100)
  25. ctx.lineTo(70, 75)
  26. ctx.setStrokeStyle('#AAAAAA')
  27. ctx.stroke()
  28. // Draw quadratic curve
  29. ctx.beginPath()
  30. ctx.moveTo(20, 20)
  31. ctx.bezierCurveTo(20, 100, 200, 100, 200, 20)
  32. ctx.setStrokeStyle('black')
  33. ctx.stroke()
  34. ctx.draw()


针对 moveTo(20, 20) bezierCurveTo(20, 100, 200, 100, 200, 20) 的三个关键坐标如下:

  • 红色:起始点(20, 20)
  • 蓝色:两个控制点(20, 100) (200, 100)
  • 绿色:终止点(200, 20)

微信小程序 canvas接口和方法绘图接口和方法

转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号