## 一、arcTo(x1, y1, x2, y2, radius)
控制點1(x1, y1)
控制點2(x2, y2)
半徑 (radius)
arcTo不能單獨使用,必須要小媳婦moveTo()配合使用才行,還是比較繞人的,還好本人花了一個簡潔明了的示意圖

很直觀,就是3連線,取兩線相切的規定半徑的圓。。

代碼如下:
~~~
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>canvas</title>
<style>
*{margin: 0;padding: 0;}
</style>
</head>
<body>
<canvas id="canvas" data-percent="10"></canvas>
<script>
var $ = document.querySelector.bind(document);
var canvas = $('#canvas'),
canvasWth = 500;
canvasHgt = 500;
canvas.width = canvasWth;
canvas.height = canvasHgt;
canvas.style.backgroundColor = '#999';
var ctx = canvas.getContext('2d');
// 白線
ctx.beginPath();
ctx.lineWidth = 1;
ctx.strokeStyle = '#fff';
ctx.moveTo(50, 20);
ctx.lineTo(150, 20);
ctx.lineTo(150, 100);
ctx.lineTo(50, 20);
ctx.closePath();
ctx.stroke();
// arcTo
ctx.lineWidth = 2;
ctx.strokeStyle = '#A7F705';
ctx.beginPath();
ctx.moveTo(150, 20);
ctx.arcTo(150,100,50,20,30);
ctx.stroke();
// 藍點
ctx.fillStyle = 'blue';
ctx.fillRect(150, 20, 10, 10);
ctx.fillStyle = '#fff';
ctx.fillText('150, 20', 170, 30);
// 藍點下紅點
ctx.fillStyle = 'red';
ctx.fillRect(150, 100, 10, 10);
ctx.fillStyle = '#fff';
ctx.fillText('150, 100', 170, 110);
// 藍點左紅點
ctx.fillStyle = 'red';
ctx.fillRect(50, 20, 10, 10);
ctx.fillStyle = '#fff';
ctx.fillText('50, 20', 10, 30);
</script>
</body>
</html>
~~~
## 二、二次貝塞爾曲線quadraticCurveTo(cpX1, cpY1, endX, endY)
控制點1(cpX1, cpY1)
結束點(endX, endY)
同上使用quadraticCurveTo()也需要moveTo()配合
示意圖

效果

代碼
~~~
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>canvas</title>
<style>
*{margin: 0;padding: 0;}
</style>
</head>
<body>
<canvas id="canvas" data-percent="10"></canvas>
<script>
var $ = document.querySelector.bind(document);
var canvas = $('#canvas'),
canvasWth = 500;
canvasHgt = 500;
canvas.width = canvasWth;
canvas.height = canvasHgt;
canvas.style.backgroundColor = '#999';
var ctx = canvas.getContext('2d');
// 綠色線
ctx.setLineDash([4, 4]);
ctx.strokeStyle = '#1AF531';
ctx.beginPath();
ctx.moveTo(75,25);
ctx.lineTo(25,25);
ctx.lineTo(25,62.5);
ctx.lineTo(75,25);
ctx.closePath();
ctx.stroke();
// quadraticCurveTo
ctx.setLineDash([0, 0]);
ctx.strokeStyle = '#f00';
ctx.beginPath();
ctx.moveTo(75,25);
ctx.quadraticCurveTo(25,25,25,62.5);
ctx.stroke();
// 白色點
ctx.fillStyle = '#fff';
ctx.fillText('75, 25', 85, 30);
ctx.fillRect(75, 25, 4, 4);
// 紅色點
ctx.fillStyle = '#f00';
ctx.fillText('25, 25', 0, 20);
ctx.fillRect(25, 25, 4, 4);
// 黃色點
ctx.fillStyle = '#F7C124';
ctx.fillText('25, 62.5', 30, 68);
ctx.fillRect(25, 62.5, 4, 4);
</script>
</body>
</html>
~~~
## 三、三次貝塞爾曲線bezierCurveTo(cpX1, cpY1, cpX2, cpY2, endX, endY)
與二次貝塞爾曲線比多了一個控制點

有了上面的經驗,這次可以嘗試簡單理解,主要就是在moveTo(x, y) 與 (endX, endY) 兩點間,加兩個控制點(cpX1, cpY1)(cpX2, cpY2)
下面用bezierCurveTo()繪制青蘋果

~~~
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>canvas</title>
<style>
*{margin: 0;padding: 0;}
</style>
</head>
<body>
<canvas id="canvas" data-percent="10"></canvas>
<script>
var $ = document.querySelector.bind(document);
var canvas = $('#canvas'),
canvasWth = 500;
canvasHgt = 500;
canvas.width = canvasWth;
canvas.height = canvasHgt;
canvas.style.backgroundColor = '#999';
var ctx = canvas.getContext('2d');
//三次貝塞爾曲線
var gradient = ctx.createLinearGradient(0,0,200,0);
gradient.addColorStop(0, "green");
gradient.addColorStop(1, "white");
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.moveTo(75,40);
ctx.bezierCurveTo(75,37,70,25,50,25);
ctx.bezierCurveTo(20,25,20,62.5,20,62.5);
ctx.bezierCurveTo(20,80,40,102,75,120);
ctx.bezierCurveTo(110,102,130,80,130,62.5);
ctx.bezierCurveTo(130,62.5,130,25,100,25);
ctx.bezierCurveTo(85,25,75,37,75,40);
ctx.fill();
</script>
</body>
</html>
~~~
結束,,拖地嘍~~~

- 事件
- mouse縮放與拖動
- drag拖動
- 事件兼容
- animation/transition
- canvas
- 改變圖片顏色
- html轉圖片
- 視頻操作
- 圖片縮放、水印、放大鏡
- 虛線
- 圓環進度條
- 形狀事件
- 圓角矩形
- 繪制注意
- arcTo與貝塞爾
- 橢圓及橢圓進度
- 五角星進度
- 常用圖形
- 計算顯示文本寬度
- 算法
- 幾何算法
- 地圖應用相關
- 運行符
- web安全
- 新窗口打開
- xss
- 分享交流
- php環境搭建及xhr交互
- node環境搭建及xhr交互
- node之socketio
- svg之入門介紹
- svg動畫
- vue之搜索聯想
- vue之登錄和echarts
- vue之組件交互與slot
- vue之loading
- vue之上傳進度
- webpack及cli
- 開發技巧
- 常用
- 移動端
- 錯誤處理
- 預加載
- 代理判斷
- 數組擴展
- 對象擴展
- 字符串擴展
- 語音播報
- 收集
- 文章/日記
- 框架/庫/插件
- 工具
- 學習網站
- 專業術語
- 正則
- 常用驗證
- 方法基礎
- es6擴展
- 深入實踐
- 快捷使用
- html
- css
- http協議
- http
- https
- socket
- 地圖/圖表
- mapbox
- echarts
- arcgis
- MapView及事件
- 添加WMS/WMTS層
- 增刪點線面
- 入門使用
- popup彈層
- 大數據處理
- 批量點
- 批量線
- 在線繪制
- GraphicLayer顯示/隱藏
- 動態改變位置
- 去除版權信息
- 添加控件
- Symbol
- 自定義path標記
- 圖片標記
- 文本標記
- 旋轉
- UI
- 自定義
- 3D地圖
- 創建實例
- basemap
- 底圖切換
- 自定義底圖
- 中心和范圍
- pupup彈層更新
- 坐標轉換
- 方向線
- leaflet
- amap
- 框架/類庫/腳手架
- vue
- 常見問題
- 組件框架
- vue-router
- 命名視圖
- url參數映射到prop
- sublime支持
- 隨手記
- 常用功能
- threejs
- 常用效果
- 其他特效
- requirejs
- 簡單使用
- jquery
- 方法擴展
- 使用筆記
- 組件擴展
- react
- 黨見問題
- 學習筆記
- 學習筆記-進階
- react-redux
- react-router
- redux
- 其他模塊說明
- 組件框架
- sublime支持
- gulp
- 安裝使用
- js壓縮
- css壓縮
- 組合使用
- copy文件
- 項目使用
- protobuf
- 入門
- layui
- 登錄驗證
- laydate
- 安裝工具
- yarn
- reactNative
- 入門介紹
- vueNative
- 入門介紹
- 版本控制
- git常用
- git擴展
- git問題
- git其他
- git擴展2
- 編輯器
- vscode
- atom
- webstorm
- 插件
- clipboard
- 奇淫巧技
- js
- 個性打印
- css
- 濾鏡效果
- 文本省略
- 當前色
- 新特性
- 花樣邊框效果
- 波紋效果
- 個性placeholder
- 偽元素內容
- 容器居中
- 知識點
- js
- 遞歸
- 沙箱
- 內存泄漏
- es6語法
- 變量介紹
- FileRead
- ajax
- web存儲
- css
- rem布局