当前位置:网站首页>Fabric. JS gradient
Fabric. JS gradient
2022-07-02 05:18:00 【Director of Moral Education Department】
stay Vue3 Use in Fabric.js Achieve gradient (Gradient) effect , Including radial gradient radial
Fabric.js brief introduction
In official terms
Fabric.js
It's a powerful and simpleJavascript HTML5 canvas
Tool library
Simply speaking , If you need to use canvas
Do special effects or interaction , Then try Fabric.js
This library , It will make development easier and intuitive .
Fabric.js Official website Fabric.js npm Address Fabric.js github Address
The development environment used in this article
In this case, we use Fabric.js 4.6
This version .
Used Vite
structure Vue3
project .
Set up the project
npm init @vitejs/app
choice Vue3
, Then initialize the project according to the prompt .
install Fabric.js
npm install fabric --save
Why is this article only about gradients ?
The gradient yes Fabric.js
The basic function of , But most articles on the Internet only write Linear gradient , Few write Radial Gradient Of , Because the official doesn't seem to give Radial Gradient Example .
I've even seen some articles and comments saying Fabric.js
Only support Linear gradient . But this statement is wrong !!!
Take a look at this case :【Fabric.js Gradient effect 】
you 're right , This paper only wants to prove that in Fabric.js
4.6 In this version, you can realize Radial Gradient Of .
Linear gradient linear
<template> <canvas width="600" height="600" id="canvas" style="border: 1px solid #ccc;"></canvas></template><script setup>import { onMounted } from 'vue'import { fabric } from 'fabric'function init() { let canvas = new fabric.Canvas('canvas') // Instantiation fabric, And bind to canvas Element // round let circle = new fabric.Circle({ left: 100, top: 100, radius: 50, }) // Linear gradient let gradient = new fabric.Gradient({ type: 'linear', // linear or radial gradientUnits: 'pixels', // pixels or pencentage Pixels perhaps percentage coords: { x1: 0, y1: 0, x2: circle.width, y2: 0 }, // At least 2 Two coordinate pairs (x1,y1 and x2,y2) Defines how the gradient extends over the object colorStops:[ // Defines an array of gradient colors { offset: 0, color: 'red' }, { offset: 0.2, color: 'orange' }, { offset: 0.4, color: 'yellow' }, { offset: 0.6, color: 'green' }, { offset: 0.8, color: 'blue' }, { offset: 1, color: 'purple' }, ] }) circle.set('fill', gradient); canvas.add(circle)}onMounted(() => { init()})</script>
Radial Gradient radial
<template> <canvas width="600" height="600" id="canvas" style="border: 1px solid #ccc;"></canvas></template><script setup>import { onMounted } from 'vue'import { fabric } from 'fabric'function init() { let canvas = new fabric.Canvas('canvas') // Instantiation fabric, And bind to canvas Element // round let circle = new fabric.Circle({ left: 100, top: 100, radius: 50, }) let gradient = new fabric.Gradient({ type: 'radial', coords: { r1: 50, // This attribute is only available for radial gradients , The radius of the outer circle r2: 0, // This attribute is only available for radial gradients , The radius of the outer circle x1: 50, // Focal x coordinate y1: 50, // Focal y coordinate x2: 50, // Center point x coordinate y2: 50, // Center point y coordinate }, colorStops: [ { offset: 0, color: '#fee140' }, { offset: 1, color: '#fa709a' } ] }) circle.set('fill', gradient); canvas.add(circle)}onMounted(() => { init()})</script>
r1
、r2
、x1
、y1
、x2
、y2
You can modify the values of these parameters and see the effect , If you change it yourself, you will understand it more deeply .
Warehouse address
This article is an online example
give the thumbs-up + Focus on + Collection = Learned to
边栏推荐
- Summary of database problems
- 4. Flask cooperates with a tag to link internal routes
- Storage of data
- Mathematical problems (number theory) trial division to judge prime numbers, decompose prime factors, and screen prime numbers
- leetcode存在重复元素go实现
- Using Kube bench and Kube hunter to evaluate the risk of kubernetes cluster
- paddle: ValueError:quality setting only supported for ‘jpeg‘ compression
- Fabric.js 居中元素
- Foreign trade marketing website system development function case making
- 函数中使用sizeof(arr) / sizeof(arr[0])求数组长度不正确的原因
猜你喜欢
[common error] the DDR type of FPGA device is selected incorrectly
The El cascader echo only selects the questions that are not displayed
【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘
LeetCode 1175. 质数排列(质数判断+组合数学)
Mysql基础---查询(1天学会mysql基础)
6.网络-基础
Collectors.groupingBy 排序
[bus interface] Axi interface
Mathematical knowledge -- understanding and examples of fast power
指针使用详解
随机推荐
Fabric.js 将本地图像上传到画布背景
Leetcode basic programming: array
函数中使用sizeof(arr) / sizeof(arr[0])求数组长度不正确的原因
2022阿里巴巴全球数学竞赛 第4题 虎虎生威(盲盒问题、集卡问题)解决思路
Basic differences between Oracle and MySQL (entry level)
Latest: the list of universities and disciplines for the second round of "double first-class" construction was announced
Mysql基础---查询(1天学会mysql基础)
Php/js cookie sharing across domains
Gee: explore the characteristics of precipitation change in the Yellow River Basin in the past 10 years [pixel by pixel analysis]
6. Network - Foundation
[common error] the DDR type of FPGA device is selected incorrectly
Mathematical problems (number theory) trial division to judge prime numbers, decompose prime factors, and screen prime numbers
Gee series: unit 9 generate sampling data in GEE [random sampling]
Video cover image setting, put cover images into multiple videos in the simplest way
7.TCP的十一种状态集
Fabric.js 圆形笔刷
Using QA band and bit mask in Google Earth engine
运维工作的“本手、妙手、俗手”
C # picture display occupancy problem
Set the default style of scroll bar Google browser