当前位置:网站首页>Fabric. JS round brush
Fabric. JS round brush
2022-07-02 05:18:00 【Director of Moral Education Department】
Brief introduction
give the thumbs-up + Focus on + Collection = Learned to
<br>
In this paper, Fabric.js
Circular brush function of .
The circular brush is used to “ Freehand drawing ” On the brush of . You can tell by the name , This brush will fill the painted path with circles .
It will be more intuitive to look at the pictures
Fabric.js
Will use different frequencies 、 size 、 Color depth to draw the above effect .
<br>
This article USES the
Fabric.js 5.2.1
<br>
<br>
Common configuration
To make the effect of the above figure , First, you need to set the canvas to Painting mode .
<br>
Initialize canvas
First, you need to initialize the canvas , After that, each attribute and method will be explained , Will be based on this code .
<canvas id="c" width="600" height="400" style="border: 1px solid #ccc;"></canvas><!-- introduce Fabric.js --><script src="https://cdn.bootcdn.net/ajax/libs/fabric.js/521/fabric.js"></script><script> // How to write it 1 const canvas = new fabric.Canvas('c', { isDrawingMode: true // Turn on painting mode }) // How to write it 2 // const canvas = new fabric.Canvas('c') // canvas.isDrawingMode = true</script>
To set the canvas to Painting mode , Need to put isDrawingMode
Set to true
.
Choose one of the above two ways to write .
<br>
Turn on the round brush
Setting the brush to round also has 2 Species writing .
<br>
How to write it 1
// Omit the initialization code canvas.freeDrawingBrush = new fabric.CircleBrush(canvas)
<br>
How to write it 2
// Omit the initialization code let circleBrush = new fabric.CircleBrush()circleBrush.initialize(canvas)canvas.freeDrawingBrush = circleBrush
<br>
Either of the above two ways can be used , But it will affect the amount of subsequent code .
If you want to modify the brush properties frequently in the future , I suggest using How to write it 2 .
<br>
Set the brush width
If you use the above step How to write it 1 , To set the brush width, you need to write this
// Omit the initialization code canvas.freeDrawingBrush = new fabric.CircleBrush(canvas) // Create a circular brush canvas.freeDrawingBrush.width = 6 // brush width , Default 10
<br>
If you use How to write it 2 , The set code is as follows
// Omit the initialization code // Create a circular brush let circleBrush = new fabric.CircleBrush()circleBrush.initialize(canvas)canvas.freeDrawingBrush = circleBrushcircleBrush.width = 30
<br>
Set brush color
// Omit the initialization code circleBrush.color = 'pink'
I set the brush to pink , Except for keyword color , And support rgb
Etc
circleBrush.color = '#c123a8'circleBrush.color = 'rgb(10, 230, 120)'
<br>
Set shadow
// Omit the initialization code circleBrush.shadow = new fabric.Shadow({ blur: 10, // The degree of eclosion offsetX: 20, // x Shaft offset offsetY: 20, // y Shaft offset color: '#30e3ca' // Projection color })
and Basic brush The method of setting shadows is the same .
<br>
<br>
Common methods
There are several common methods , But there are some things that need attention , To be effective, use it in combination .
<br>
The mouse click
// Omit the initialization code circleBrush.onMouseDown = function (pointer, e) { console.log(pointer) console.log(e)}
Use onMouseDown
You can set the event to be triggered when the mouse is pressed . The event has 2 Parameters .
<br>
Release the mouse
// Omit the initialization code circleBrush.onMouseUp = function (pointer) { console.log(pointer)}
and “ The mouse click ” It's as simple as . Use onMouseUp
You can set the event of mouse release .
<br>
When the mouse moves
// Omit the initialization code circleBrush.onMouseMove = function (pointer, e) { console.log(pointer) console.log(e) circleBrush.drawDot(pointer)}
Use onMouseMove
You can set the event when the mouse moves . However, in this event, it is necessary to perform drawDot
event , And pass in the current mouse position to draw correctly .
<br>
More methods can be added to mouse movement events , For example, on the basis of drawing , Draw another line nearby
// Omit the initialization code circleBrush.onMouseMove = function (pointer, e) { console.log(pointer) console.log(e) circleBrush.drawDot(pointer) circleBrush.addPoint({x: pointer.x + 50, y: pointer.y + 50}) // There is one more line nearby }
That's all Fabric
Common playing methods of round brushes ~
<br>
<br>
Code warehouse
<br>
<br>
Recommended reading
- 《Fabric.js How to use the brush ?》
- 《Fabric.js Draw ellipses freely 》
- 《Fabric.js How to use an eraser ( Including recovery function )》
- 《Fabric.js Customize the right-click menu 》
- 《Fabric.js From entry to expansion 》
give the thumbs-up + Focus on + Collection = Learned to
边栏推荐
- [common error] the DDR type of FPGA device is selected incorrectly
- 从数组中找出和为目标的下标
- 画波形图_数字IC
- Leetcode basic programming: array
- 2022 Alibaba global mathematics competition, question 4, huhushengwei (blind box problem, truck problem) solution ideas
- No logic is executed after the El form is validated successfully
- LS1046nfs挂载文件系统
- Pyechats 1.19 generate a web version of Baidu map
- Fabric.js IText 上标和下标
- Splice characters in {{}}
猜你喜欢
Using QA band and bit mask in Google Earth engine
Gee series: unit 7 remote sensing image classification using GEE [random forest classification]
Super detailed pycharm tutorial
Record my pytorch installation process and errors
LeetCode 1175. Prime number arrangement (prime number judgment + Combinatorial Mathematics)
黑馬筆記---Set系列集合
Pyechats 1.19 generate a web version of Baidu map
【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘
6. Network - Foundation
Fabric.js IText 上标和下标
随机推荐
Save the CDA from the disc to the computer
Global and Chinese market of impact roll 2022-2028: Research Report on technology, participants, trends, market size and share
Video cover image setting, put cover images into multiple videos in the simplest way
Global and Chinese market of cell culture freezers 2022-2028: Research Report on technology, participants, trends, market size and share
国产全中文-自动化测试软件Apifox
How to configure PostgreSQL 12.9 to allow remote connections
Gee: create a new feature and set corresponding attributes
7.1 Résumé du concours de simulation
延时队列两种实现方式
Operator details
Pyechats 1.19 generate a web version of Baidu map
Mapping settings in elk (8) es
黑馬筆記---Set系列集合
摆正元素(带过渡动画)
Video multiple effects production, fade in effect and border background are added at the same time
将光盘中的cda保存到电脑中
[common error] the DDR type of FPGA device is selected incorrectly
MMAP zero copy knowledge point notes
Simple and practical accounting software, so that accounts can be checked
Fabric.js 激活输入框