43 Star 957 Fork 264

德育处主任/前端数据可视化

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Gradient.vue 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
德育处主任 提交于 4年前 . fabric 径向渐变
<template>
<div>
<canvas width="600" height="600" id="canvas" style="border: 1px solid #ccc;"></canvas>
</div>
</template>
<script setup>
import { onMounted } from 'vue'
import { useStore } from 'vuex'
import { fabric } from 'fabric'
const store = useStore()
function init() {
let canvas = new fabric.Canvas('canvas')
// 圆
let circle1 = new fabric.Circle({
left: 100,
top: 100,
radius: 50,
})
let gradient1 = new fabric.Gradient({
type: 'linear', // linear or radial
gradientUnits: 'pixels', // pixels or pencentage 像素 或者 百分比
coords: { x1: 0, y1: 0, x2: circle1.width, y2: 0 }, // 至少2个坐标对(x1,y1和x2,y2)将定义渐变在对象上的扩展方式
colorStops:[ // 定义渐变颜色的数组
{ 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' },
]
})
circle1.set('fill', gradient1);
canvas.add(circle1)
// 径向渐变的圆
let circle2 = new fabric.Circle({
left: 300,
top: 100,
radius: 50
})
let gradient2 = new fabric.Gradient({
type: 'radial',
coords: {
r1: 50,
r2: 0,
x1: 50,
y1: 50,
x2: 50,
y2: 50,
},
colorStops: [
{ offset: 0, color: '#fee140' },
{ offset: 1, color: '#fa709a' }
]
})
circle2.set('fill', gradient2);
canvas.add(circle2)
}
onMounted(() => {
store.commit('setComponentPath', 'src/views/FabricJS/Basic/pages/Gradient/Gradient.vue')
init()
})
</script>
<style lang="scss" scoped>
</style>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/k21vin/front-end-data-visualization.git
git@gitee.com:k21vin/front-end-data-visualization.git
k21vin
front-end-data-visualization
前端数据可视化
master

搜索帮助