1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| <!DOCTYPE html> <html>
<head> <title>变形操作(rotate)</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content="图形系统开发实战:基础篇 示例"> <meta name="author" content="hjq"> <meta name="keywords" content="canvas,ladder,javascript"> <script src="./js/helper.js"></script> </head>
<body style="overflow: hidden; margin:0px;"> <div style="display: inline-block; margin:10px;"> <canvas id="canvas1" width="210" height="280" style="border:solid 1px #CCCCCC;"></canvas> <canvas id="canvas2" width="210" height="280" style="border:solid 1px #CCCCCC;"></canvas> <canvas id="canvas3" width="210" height="280" style="border:solid 1px #CCCCCC;"></canvas> <canvas id="canvas4" width="210" height="280" style="border:solid 1px #CCCCCC;"></canvas> </div> </body> <script> function main(img) { let canvas1 = document.getElementById('canvas1'); let ctx1 = canvas1.getContext('2d'); drawGrid('lightgray', 10, 10, ctx1); ctx1.font = "24px 黑体"; ctx1.fillText("原图", 80, 255); ctx1.drawImage(img, 60, 50);
let canvas2 = document.getElementById('canvas2'); let ctx2 = canvas2.getContext('2d'); drawGrid('lightgray', 10, 10, ctx2); ctx2.font = "24px 黑体"; ctx2.fillText("水平翻转", 60, 255); ctx2.scale(-1, 1); ctx2.translate(-canvas2.width, 0); ctx2.drawImage(img, 60, 50);
let canvas3 = document.getElementById('canvas3'); let ctx3 = canvas3.getContext('2d'); drawGrid('lightgray', 10, 10, ctx3); ctx3.font = "24px 黑体"; ctx3.fillText("垂直翻转", 60, 255); ctx3.scale(1, -1); ctx3.translate(0, -canvas3.height); ctx3.drawImage(img, 60, 50);
let canvas4 = document.getElementById('canvas4'); let ctx4 = canvas4.getContext('2d'); drawGrid('lightgray', 10, 10, ctx4); ctx4.font = "24px 黑体"; ctx4.fillText("水平+垂直翻转", 30, 255); ctx4.scale(-1, -1); ctx4.translate(-canvas4.width, -canvas4.height); ctx4.drawImage(img, 60, 50); }
let image = new Image(); image.onload = function () { main(image); } image.src = "./images/man2b.svg"; </script>
</html>
|