let canvas = new fabric.Canvas('canvas', { backgroundColor: 'grey' })
// 画正方形
let rect = new fabric.Rect({
left: 100,
top: 100,
fill: 'red',
width: 20,
height: 20,
angle: 45
})
canvas.add(rect)
2. 画圆
javascript复制代码
let canvas = new fabric.Canvas('canvas', { backgroundColor: 'grey' })
// 画圆
let circle = new fabric.Circle({
left: 100,
top: 100,
fill: 'green',
width: 20,
height: 20,
radius: 20
})
canvas.add(circle)
3. 画三角形
javascript复制代码
let canvas = new fabric.Canvas('canvas', { backgroundColor: 'grey' })
// 画三角形
let triangle = new fabric.Triangle({
width: 20,
height: 30,
fill: 'blue',
left: 50,
top: 50
})
canvas.add(triangle)
4. 画椭圆
javascript复制代码
let canvas = new fabric.Canvas('canvas', { backgroundColor: 'grey' })
// 画椭圆
let ellipse = new fabric.Ellipse({
rx: 20,
ry: 30,
left: 200,
top: 200,
fill: '#87ceed'
})
canvas.add(ellipse)
5. 画线
javascript复制代码
let canvas = new fabric.Canvas('canvas', { backgroundColor: 'grey' })
// 画线
let line = new fabric.Line([70, 100, 150, 200], {
stroke: 'blue'
})
canvas.add(line)