Upgrade to Pro — share decks privately, control downloads, hide ads and more …

HTML5_canvas_PIXNET

CypressKuo
October 07, 2016

 HTML5_canvas_PIXNET

CypressKuo

October 07, 2016
Tweet

More Decks by CypressKuo

Other Decks in Technology

Transcript

  1. <canvas> Added in HTML5, the HTML <canvas> element can be

    used to draw graphics via scripting in JavaScript. For example, it can be used to draw graphs, make photo compositions, create animations, or even do real-time video processing or rendering. 2 https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API 2
  2. <canvas id="canvas" width="1024" height="768"> 本瀏覽器不⽀支援 canvas,請升級! </canvas> var canvas =

    document.getElementById("canvas"); canvas.width = 1024; canvas.height = 768; 錯誤替代內容 (Fallback content) 4
  3. 矩形 context.fillRect(25, 25, 100, 100); context.clearRect(45, 45, 60, 60); context.strokeRect(50,

    50, 50, 50); 畫出⼀一個填滿的矩形 清除矩形區域 畫出⼀一個只有框的矩形 (左上⾓角 x 坐標, 左上⾓角 y 坐標, 寬, ⾼高) 7 7
  4. context.beginPath(); context.moveTo(100, 100); context.lineTo(700, 700); context.lineTo(100, 700); context.lineTo(100, 100); context.closePath();

    開始繪製(產⽣生路路徑) 移動到 100, 100 開始 移動⾄至 700, 700 再移動⾄至 100, 700 最後移動⾄至 100, 100 結束繪製(閉合路路徑) 路路徑 8 8
  5. 弧形 context.arc(300, 300, 200, 0, 1.5 * Math.PI, true); (圓⼼心

    x 坐標, 圓⼼心 y 坐標, 半徑, 開啟位置, 結束位置, 是否逆時針) 11 11
  6. ⾙貝茲曲線 context.quadraticCurveTo(25, 100, 50, 100); (控制點 x 坐標, 控制點 y

    坐標, 結束位置 x 坐標, 結束位置 y 坐標) context.bezierCurveTo(20, 80, 40, 100, 75, 120); (第⼀一控制點 x 坐標, 第⼀一控制點 y 坐標, 第⼆二控制點 x 坐標, 第⼆二控制點 y 坐標, 結束位置 x 坐標, 結束位置 y 坐標) 13 13
  7. 物件化 new Path2D(); new Path2D(path); new Path2D(d); Path2D object API:

    https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D#Paths 代入路路徑 SVG 路路徑 15 15