Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
canvas.width = 100;
canvas.height = 100;
const context = canvas.getContext('2d');
context.fillStyle = 'red';
context.fillRect(0, 0, 100, 100);
const ellipse = new Path2D(canvas);
ellipse.ellipse(50, 50, 25, 35, (45 * Math.PI) / 180, 0, 2 * Math.PI);
context.fillStyle = 'purple';
context.fill(ellipse);
context.save();
context.scale(0.5, 0.5);
context.translate(50, 20);
const rectPath = new Path2D(canvas, 'M10 10 h 80 v 80 h -80 Z');
context.fillStyle = 'pink';
context.fill(rectPath);
context.restore();
}
handlePath(canvas) {
canvas.width = 100;
canvas.height = 100;
const context = canvas.getContext('2d');
context.fillStyle = 'red';
context.fillRect(0, 0, 100, 100);
const ellipse = new Path2D(canvas);
ellipse.ellipse(50, 50, 25, 35, (45 * Math.PI) / 180, 0, 2 * Math.PI);
context.fillStyle = 'purple';
context.fill(ellipse);
context.save();
context.scale(0.5, 0.5);
context.translate(50, 20);
const rectPath = new Path2D(canvas, 'M10 10 h 80 v 80 h -80 Z');
context.fillStyle = 'pink';
context.fill(rectPath);
context.restore();
}