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
| <!DOCTYPE html> <html>
<head> <title>变形操作(skew)</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:10px;"> <canvas id="canvas" width="700" height="300" style="border:solid 1px #CCCCCC;"></canvas> </body> <script> let canvas = document.getElementById('canvas'); let ctx = canvas.getContext('2d'); drawGrid('lightgray', 10, 10);
let x = 150, y = 50, width = 400, height = 200;
ctx.lineWidth = 4; ctx.strokeStyle = "#A2A2A2"; ctx.strokeRect(x, y, width, height);
let cx = x + width / 2, cy = y + height / 2; ctx.translate(cx, cy); ctx.transform(1, 0, toRadians(45), 1, 0, 0); ctx.translate(-cx, -cy); ctx.strokeStyle = "blue"; ctx.strokeRect(x, y, width, height);
</script>
</html>
|