课程表

微信小程序框架

微信小程序组件

微信小程序API

微信小程序开放接口

微信小程序工具

微信小程序设计规范

工具箱
速查手册

小程序API 画弧线

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

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

arc


定义

画一条弧线。

Tip: 创建一个圆可以用 arc() 方法指定其实弧度为0,终止弧度为 2 * Math.PI

Tip: 用 stroke() 或者 fill() 方法来在 canvas 中画弧线。

参数

参数类型说明
xNumber圆的x坐标
yNumber圆的y坐标
rNumber圆的半径
sAngleNumber起始弧度,单位弧度(在3点钟方向)
eAngleNumber终止弧度
counterclockwiseBoolean可选。指定弧度的方向是逆时针还是顺时针。默认是false,即顺时针。

例子

  1. const ctx = wx.createCanvasContext('myCanvas')
  2. // Draw coordinates
  3. ctx.arc(100, 75, 50, 0, 2 * Math.PI)
  4. ctx.setFillStyle('#EEEEEE')
  5. ctx.fill()
  6. ctx.beginPath()
  7. ctx.moveTo(40, 75)
  8. ctx.lineTo(160, 75)
  9. ctx.moveTo(100, 15)
  10. ctx.lineTo(100, 135)
  11. ctx.setStrokeStyle('#AAAAAA')
  12. ctx.stroke()
  13. ctx.setFontSize(12)
  14. ctx.setFillStyle('black')
  15. ctx.fillText('0', 165, 78)
  16. ctx.fillText('0.5*PI', 83, 145)
  17. ctx.fillText('1*PI', 15, 78)
  18. ctx.fillText('1.5*PI', 83, 10)
  19. // Draw points
  20. ctx.beginPath()
  21. ctx.arc(100, 75, 2, 0, 2 * Math.PI)
  22. ctx.setFillStyle('lightgreen')
  23. ctx.fill()
  24. ctx.beginPath()
  25. ctx.arc(100, 25, 2, 0, 2 * Math.PI)
  26. ctx.setFillStyle('blue')
  27. ctx.fill()
  28. ctx.beginPath()
  29. ctx.arc(150, 75, 2, 0, 2 * Math.PI)
  30. ctx.setFillStyle('red')
  31. ctx.fill()
  32. // Draw arc
  33. ctx.beginPath()
  34. ctx.arc(100, 75, 50, 0, 1.5 * Math.PI)
  35. ctx.setStrokeStyle('#333333')
  36. ctx.stroke()
  37. ctx.draw()


针对 arc(100, 75, 50, 0, 1.5 * Math.PI)的三个关键坐标如下:

  • 绿色: 圆心 (100, 75)
  • 红色: 起始弧度 (0)
  • 蓝色: 终止弧度 (1.5 * Math.PI)

微信小程序 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号