canvas setTransform()方法
此方法的語法格式和transform()方法是完全一樣的。
關於transform()方法的用法可以參閱canvas transform()一章節。
[HTML] 純文字檢視 複製程式碼執行程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style> canvas { border: 2px dotted #ccc; margin: 50px; } </style> <script> window.onload = function () { var cvs = document.getElementById("canvas"); var ctx = cvs.getContext("2d"); var angle = Math.PI / 180; ctx.fillStyle = "yellow"; ctx.fillRect(0, 0, 250, 100) ctx.setTransform(Math.cos(30*angle),Math.sin(30*angle),-Math.sin(30*angle),Math.cos(30*angle),30,10); ctx.fillStyle = "red"; ctx.fillRect(0, 0, 250, 100); ctx.setTransform(Math.cos(30*angle),Math.sin(30*angle),-Math.sin(30*angle), Math.cos(30*angle),30,10); ctx.fillStyle = "blue"; ctx.fillRect(0, 0, 250, 100); } </script> </head> <body> <canvas id="canvas" width="400" height="250"></canvas> </body> </html>
在上面的程式碼中,我們並沒有看到紅色的矩形,因為它被藍色矩形所覆蓋。
這就體現出此方法與transform()方法的不同之處(也是唯一的區別),那就是setTransform()方法會重置前面的矩陣,然後再繪製出一個新的矩陣;transform()方法則不會重置前面的矩陣,而是在前面的基礎上繼續進行縮放、唯一或者旋轉。
相關文章
- canvas setTransform()CanvasORM
- canvas isPointInPath()方法Canvas
- canvas arc()方法詳解Canvas
- canvas closePath()方法詳解Canvas
- canvas getContext()方法CanvasContext
- Canvas之translate、scale、rotate、skew方法講解!Canvas
- canvas translate()、scale()和rotate()方法程式碼例項Canvas
- canvasCanvas
- flutter自定義View(CustomPainter) 之 canvas的方法總結FlutterViewAICanvas
- html5中的canvas繪製橢圓的方法HTMLCanvas
- canvas clearRect()Canvas
- canvas toBlob()Canvas
- canvas toDataURL()Canvas
- canvas stroke()Canvas
- canvas fill()Canvas
- canvas fillRect()Canvas
- canvas translate()Canvas
- canvas rotate()Canvas
- canvas scale()Canvas
- canvas fillText()Canvas
- canvas createPattern()Canvas
- canvas createImageData()Canvas
- canvas restore()CanvasREST
- canvas save()Canvas
- canvas putImageData()Canvas
- canvas drawImage()Canvas
- canvas clip()Canvas
- canvas arcTo()Canvas
- canvas isPointInPath()Canvas
- canvas arc()Canvas
- canvas getImageData()Canvas
- canvas fillStyleCanvas
- canvas closePath()Canvas
- canvas beginPath()Canvas
- canvas strokeRect()Canvas
- canvas strokeStyleCanvas
- canvas rect()Canvas
- canvas(三)Canvas