OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <body> |
| 4 <canvas id ='output' width='150' height='150'></canvas> |
| 5 <script> |
| 6 var aCanvas = document.getElementById('output'); |
| 7 var ctx = aCanvas.getContext('2d'); |
| 8 |
| 9 var patternCanvas = document.createElement('canvas'); |
| 10 patternCanvas.width = 30; |
| 11 patternCanvas.height = 30; |
| 12 var patternCtx = patternCanvas.getContext('2d'); |
| 13 patternCtx.fillStyle = '#f00';
|
| 14 patternCtx.fillRect(0, 0, 15, 15); |
| 15 patternCtx.fillStyle = '#0f0';
|
| 16 patternCtx.fillRect(15, 0, 15, 15); |
| 17 patternCtx.fillStyle = '#00f'; |
| 18 patternCtx.fillRect(0, 15, 15, 15); |
| 19 patternCtx.fillStyle = "#ff0"; |
| 20 patternCtx.fillRect(15, 15, 15, 15); |
| 21 |
| 22 var myPattern = ctx.createPattern(patternCanvas, 'repeat'); |
| 23 ctx.fillStyle = myPattern; |
| 24 ctx.fillRect(0, 0, aCanvas.width, aCanvas.height); |
| 25 </script> |
| 26 </body> |
| 27 </html> |
OLD | NEW |