[TOC]
# 圓形
`CanvasRenderingContext2D.arc()`用來繪制圓弧。由于圓本質上就是個封閉圓弧,因此,此方法也可以用來繪制正圓。
語法:
```js
context.arc(x, y, radius, startAngle, endAngle [, anticlockwise]);
```
參數解釋:
- x *Number*:圓弧對應的圓心橫坐標
- y *Number*:圓弧對應的圓心縱坐標
- radius *Number*:圓弧的半徑大小
- startAngle *Number*:圓弧開始的角度,單位是弧度
- endAngle *Number*:圓弧結束的角度,單位是弧度
- anticlockwise(可選) *Boolean*:弧度的繪制是按順時針還是逆時針,默認值為 false,表示按順時針方向繪制
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>圓形</title>
</head>
<body>
<canvas id="canvas" width="200" height="150" style="border: 1px dashed gray;"></canvas>
</body>
</html>
<script>
window.onload = function () {
let cnv = document.getElementById('canvas')
let cxt = cnv.getContext('2d')
cxt.beginPath()
cxt.arc(120, 80, 50, 0, 360*Math.PI/180, true) // 120*Math.PI/180 表示 120°
cxt.strokeStyle = 'HotPink'
cxt.stroke() // 使用 stroke() 來描邊
cxt.closePath()
cxt.beginPath()
cxt.arc(30, 30, 30, 0, 360*Math.PI/180, true)
cxt.fillStyle = '#9966FF'
cxt.fill() // 使用 fill() 來填充
}
</script>
```
繪制效果如下:

# 弧線
弧線可以使用`arc()`和`arcTo()`方法來繪制。
## arc()
我們使用`arc()`方法繪制弧線時需要注意不適用`closePath()`來關閉路徑,否則圖形會自動閉合。
```js
cxt.beginPath()
cxt.arc(50, 50, 50, 0, 60*Math.PI/180, false)
cxt.stroke()
```

如果加上`closePath()`效果是這樣的:
```js
cxt.beginPath()
cxt.arc(50, 50, 50, 0, 60*Math.PI/180, false)
cxt.closePath()
cxt.stroke()
```

## arcTo()
[https://www.canvasapi.cn/CanvasRenderingContext2D/arcTo#&syntax](https://www.canvasapi.cn/CanvasRenderingContext2D/arcTo#&syntax)
```js
context.arcTo(x1, y1, x2, y2, radius)
```
參數說明:
- x1 *Number*:第 1 控制點的橫坐標
- y1 *Number*:第 1 個控制點的縱坐標
- x2 *Number*:第 2 個控制點的橫坐標
- y2 *Number*:第 2 個控制點的縱坐標
- radius *Number*:圓弧的半徑大小

## 貝塞爾曲線
- 序言 & 更新日志
- H5
- Canvas
- 序言
- Part1-直線、矩形、多邊形
- Part2-曲線圖形
- Part3-線條操作
- Part4-文本操作
- Part5-圖像操作
- Part6-變形操作
- Part7-像素操作
- Part8-漸變與陰影
- Part9-路徑與狀態
- Part10-物理動畫
- Part11-邊界檢測
- Part12-碰撞檢測
- Part13-用戶交互
- Part14-高級動畫
- CSS
- SCSS
- codePen
- 速查表
- 面試題
- 《CSS Secrets》
- SVG
- 移動端適配
- 濾鏡(filter)的使用
- JS
- 基礎概念
- 作用域、作用域鏈、閉包
- this
- 原型與繼承
- 數組、字符串、Map、Set方法整理
- 垃圾回收機制
- DOM
- BOM
- 事件循環
- 嚴格模式
- 正則表達式
- ES6部分
- 設計模式
- AJAX
- 模塊化
- 讀冴羽博客筆記
- 第一部分總結-深入JS系列
- 第二部分總結-專題系列
- 第三部分總結-ES6系列
- 網絡請求中的數據類型
- 事件
- 表單
- 函數式編程
- Tips
- JS-Coding
- Framework
- Vue
- 書寫規范
- 基礎
- vue-router & vuex
- 深入淺出 Vue
- 響應式原理及其他
- new Vue 發生了什么
- 組件化
- 編譯流程
- Vue Router
- Vuex
- 前端路由的簡單實現
- React
- 基礎
- 書寫規范
- Redux & react-router
- immutable.js
- CSS 管理
- React 16新特性-Fiber 與 Hook
- 《深入淺出React和Redux》筆記
- 前半部分
- 后半部分
- react-transition-group
- Vue 與 React 的對比
- 工程化與架構
- Hybird
- React Native
- 新手上路
- 內置組件
- 常用插件
- 問題記錄
- Echarts
- 基礎
- Electron
- 序言
- 配置 Electron 開發環境 & 基礎概念
- React + TypeScript 仿 Antd
- TypeScript 基礎
- React + ts
- 樣式設計
- 組件測試
- 圖標解決方案
- Storybook 的使用
- Input 組件
- 在線 mock server
- 打包與發布
- Algorithm
- 排序算法及常見問題
- 劍指 offer
- 動態規劃
- DataStruct
- 概述
- 樹
- 鏈表
- Network
- Performance
- Webpack
- PWA
- Browser
- Safety
- 微信小程序
- mpvue 課程實戰記錄
- 服務器
- 操作系統基礎知識
- Linux
- Nginx
- redis
- node.js
- 基礎及原生模塊
- express框架
- node.js操作數據庫
- 《深入淺出 node.js》筆記
- 前半部分
- 后半部分
- 數據庫
- SQL
- 面試題收集
- 智力題
- 面試題精選1
- 面試題精選2
- 問答篇
- 2025面試題收集
- Other
- markdown 書寫
- Git
- LaTex 常用命令
- Bugs