当前位置:网站首页>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
边栏推荐
- Mysql基础---查询(1天学会mysql基础)
- 国产全中文-自动化测试软件Apifox
- Go GC garbage collection notes (three color mark)
- Summary of MySQL key challenges (2)
- Gee: explore the change of water area in the North Canal basin over the past 30 years [year by year]
- js中的Map(含leetcode例题)
- About PROFIBUS: communication backbone network of production plant
- 画波形图_数字IC
- Line by line explanation of yolox source code of anchor free series network (7) -- obj in head_ loss、Cls_ Loss and reg_ Calculation and reverse transmission of loss I
- Leetcode18题 【四数之和】递归解法
猜你喜欢
运维工作的“本手、妙手、俗手”
6.网络-基础
Here comes the chicken soup! Keep this quick guide for data analysts
Gee: create a new feature and set corresponding attributes
Fabric.js IText 手动设置斜体
Using Kube bench and Kube hunter to evaluate the risk of kubernetes cluster
Fabric.js 激活输入框
4. Flask cooperates with a tag to link internal routes
Collectors.groupingBy 排序
Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
随机推荐
Save the CDA from the disc to the computer
Preparation for writing SAP ui5 applications using typescript
Collectors. Groupingby sort
Nodejs (03) -- custom module
Video cover image setting, put cover images into multiple videos in the simplest way
7.1模拟赛总结
7.TCP的十一种状态集
线程池批量处理数据
在{{}}中拼接字符
C # picture display occupancy problem
运维工作的“本手、妙手、俗手”
Essence and physical meaning of convolution (deep and brief understanding)
Gee: remote sensing image composite and mosaic
Fabric.js 激活输入框
[common error] the DDR type of FPGA device is selected incorrectly
Fabric.js 精简JSON
函数栈帧的创建和销毁
Pyechats 1.19 generate a web version of Baidu map
Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
Global and Chinese markets for marine selective catalytic reduction systems 2022-2028: Research Report on technology, participants, trends, market size and share