1768521-1.html (607B)
1 <!DOCTYPE html> 2 <html> 3 <body> 4 <canvas id="patternCanvas" width="8" height="32"></canvas> 5 <br> 6 <canvas id="canvas" width="32" height="32"></canvas> 7 <script> 8 9 const patternCanvas = document.getElementById("patternCanvas"); 10 const patternCtx = patternCanvas.getContext("2d"); 11 patternCtx.fillStyle = "green"; 12 patternCtx.fillRect(0, 0, patternCanvas.width, patternCanvas.height); 13 14 const canvas = document.getElementById("canvas"); 15 const ctx = canvas.getContext("2d"); 16 const pattern = ctx.createPattern(patternCanvas, "repeat-x"); 17 ctx.fillStyle = pattern; 18 ctx.fillRect(16, 16, 16, 16); 19 </script> 20 21 </body> 22 </html>