✨ adding flip node
This commit is contained in:
33
src/nodes/Canvas2d/Flip.js
Normal file
33
src/nodes/Canvas2d/Flip.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import Canvas2d from './Canvas2d';
|
||||
import {createCanvas, mediaSize, paintToCanvas} from '../canvas';
|
||||
|
||||
export default class Flip extends Canvas2d {
|
||||
|
||||
constructor() {
|
||||
super('Flip', {
|
||||
horizontal: {
|
||||
type: 'Boolean',
|
||||
default: false,
|
||||
},
|
||||
vertical: {
|
||||
type: 'Boolean',
|
||||
default: false,
|
||||
},
|
||||
}, {});
|
||||
this._update();
|
||||
}
|
||||
|
||||
async render({image, horizontal, vertical}, canvas, ctx) {
|
||||
if (!image) return;
|
||||
const horizontalModifier = horizontal ? -1 : 1;
|
||||
const verticalModifier = vertical ? -1 : 1;
|
||||
const {width, height} = mediaSize(image);
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
ctx.save();
|
||||
ctx.scale(horizontalModifier, verticalModifier);
|
||||
ctx.drawImage(image, 0, 0, width * horizontalModifier, height * verticalModifier);
|
||||
ctx.restore();
|
||||
return canvas;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user