<!DOCTYPE html>
<html>
<body>
<h1>HTML5 Canvas</h1>
<h2>The clip() Method</h2>
<p>Without clip():</p>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid grey"></canvas>
<p>With clip():</p>
<canvas id="myCanvas2" width="300" height="150" style="border:1px solid grey"></canvas>
<script>
const c1 = document.getElementById("myCanvas");
const ctx1 = c1.getContext("2d");
ctx1.rect(50, 20, 200, 120);
ctx1.stroke();
ctx1.fillStyle = "red";
ctx1.fillRect(0, 0, 150, 100);
const c2 = document.getElementById("myCanvas2");
const ctx2 = c2.getContext("2d");
ctx2.rect(50, 20, 200, 120);
ctx2.stroke();
ctx2.clip();
ctx2.fillStyle = "red";
ctx2.fillRect(0, 0, 150, 100);
</script>
</body>
</html>