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