Canvas學(xué)習(xí)筆記之形狀

canvas學(xué)習(xí)筆記--by Damon

基礎(chǔ)用法

  1. 默認(rèn)寬高300x150
  2. 標(biāo)簽
  3. 渲染上下文

繪制形狀

矩形 rect

ctx.fillRect(x, y , w, h)
// x, y => position
// w, h => width and height
ctx.strokeRect
// 邊框沒有顏色
ctx.clearRect

除了矩形外都需要先建立好路徑,然后填充操作
beginPath => closePath => stroke/fill

triangle/line

ctx.moveTo(x, y)
ctx.stroke()
ctx.

arc

ctx.arc(x, y, radius, startAngle, endAngle, anticlockwise)

bezier

ctx.quadraticCurveTo(cp1x, cp1y, x, y) 
ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
// 一次和二次貝塞爾曲線, 區(qū)別,控制點一個和兩個

path2D

var path2D = new Path2D();
// 為路徑對象,存儲路徑,直到最后使用
// path2D.rect....
// ctx.fill(path2D)
Paste_Image.png

代碼地址
Demo地址

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容