当前位置:网站首页>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.jsIt's a powerful and simpleJavascript HTML5 canvasTool 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 --saveWhy 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
边栏推荐
- Paddlepaddle project source code
- Gee: create a new feature and set corresponding attributes
- Creation and destruction of function stack frames
- leetcode存在重复元素go实现
- C # picture display occupancy problem
- Global and Chinese market of pressure gauges 2022-2028: Research Report on technology, participants, trends, market size and share
- Express logistics quick query method, set the unsigned doc No. to refresh and query automatically
- 指针使用详解
- 视差特效的原理和实现方法
- Gee series: Unit 1 Introduction to Google Earth engine
猜你喜欢

Disable access to external entities in XML parsing

6. Network - Foundation
![[high speed bus] Introduction to jesd204b](/img/78/1a0a3672e63058da6d98da95aa3cf2.jpg)
[high speed bus] Introduction to jesd204b

Fabric.js IText 上标和下标

Here comes the chicken soup! Keep this quick guide for data analysts

Pycharm breakpoint management: temporarily cancel some breakpoints + run directly to a line

指针使用详解
![Gee: explore the characteristics of precipitation change in the Yellow River Basin in the past 10 years [pixel by pixel analysis]](/img/ff/59956c2323567cc614458a2bccb642.jpg)
Gee: explore the characteristics of precipitation change in the Yellow River Basin in the past 10 years [pixel by pixel analysis]

Ls1046nfs mount file system

Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
随机推荐
Ansible installation and use
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
The reason why sizeof (ARR) / sizeof (arr[0]) is used in the function to calculate the length of the array is incorrect
线程池批量处理数据
php/js cookie共享跨域的问题
Global and Chinese market of cell culture freezers 2022-2028: Research Report on technology, participants, trends, market size and share
数据的储存
Two implementation methods of delay queue
Express logistics quick query method, set the unsigned doc No. to refresh and query automatically
Gee: create a new feature and set corresponding attributes
Fabric.js 将本地图像上传到画布背景
Disable access to external entities in XML parsing
Global and Chinese markets for marine selective catalytic reduction systems 2022-2028: Research Report on technology, participants, trends, market size and share
Super detailed pycharm tutorial
Operator details
Gee series: Unit 1 Introduction to Google Earth engine
Video multiple effects production, fade in effect and border background are added at the same time
Splice characters in {{}}
el form 表单validate成功后没有执行逻辑
从数组中找出和为目标的下标