代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>圆形笔刷 CircleBrush</title>
</head>
<body>
<canvas id="c" width="600" height="400" style="border: 1px solid #ccc;"></canvas>
<script src="../../../script/fabric.js"></script>
<script>
// 初始化
const canvas = new fabric.Canvas('c')
canvas.isDrawingMode = true
// 写法1
// canvas.freeDrawingBrush = new fabric.CircleBrush(canvas)
// canvas.freeDrawingBrush.width = 6 // 笔刷宽度,默认10
// 写法2
let circleBrush = new fabric.CircleBrush()
circleBrush.initialize(canvas)
canvas.freeDrawingBrush = circleBrush
// 设置笔刷宽度
// circleBrush.width = 30
// 设置颜色
// circleBrush.color = 'pink'
// circleBrush.color = '#c123a8'
// circleBrush.color = 'rgb(10, 230, 120)'
// 设置阴影
// circleBrush.shadow = new fabric.Shadow({
// blur: 10, // 羽化程度
// offsetX: 20, // x轴偏移量
// offsetY: 20, // y轴偏移量
// color: '#30e3ca' // 投影颜色
// })
// 鼠标按下
// circleBrush.onMouseDown = function (pointer, e) {
// console.log(pointer)
// console.log(e)
// }
// 鼠标松开
// circleBrush.onMouseUp = function (pointer) {
// console.log(pointer)
// }
// 鼠标移动时
circleBrush.onMouseMove = function (pointer, e) {
console.log(pointer)
console.log(e)
circleBrush.drawDot(pointer)
circleBrush.addPoint({x: pointer.x + 50, y: pointer.y + 50})
}
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。