canvas繪製旋轉一定角度的矩形效果
分享一段程式碼例項,它實現了旋轉一定角度的矩形效果。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> </head> <body> <canvas id="myCanvas" width="300" height="150"></canvas> <script> var c = document.getElementById("myCanvas"); var context = c.getContext("2d"); //繪製黑色矩形 context.fillStyle = "black"; context.fillRect(20, 20, 25, 25); context.setTransform(1, 0, 0, 1, 0, 0); var angleInRadians = 45 * Math.PI / 180; var x = 100; var y = 100; var width = 50; var height = 50; context.translate(x + .5 * width, y + .5 * height); //改變原點 context.rotate(angleInRadians); //旋轉角度 context.fillStyle = "red"; context.fillRect(-.5 * width, -.5 * height, width, height); </script> </body> </html>
相關文章
- canvas 繪製旋轉一定角度的矩形Canvas
- canvas 繪製矩形Canvas
- canvas 繪製圓角矩形Canvas
- canvas 繪製矩形缺角Canvas
- canvas繪製矩形框Canvas
- canvas系列教程之繪製矩形Canvas
- html5中canvas繪製矩形HTMLCanvas
- canvas實現手動繪製矩形Canvas
- CAD繪製帶角度的矩形陣列陣列
- canvas繪製流星效果Canvas
- CSS3實現的div元素旋轉一定角度效果CSSS3
- 微信小程式 canvas圓角矩形的繪製微信小程式Canvas
- canvas繪製風車效果Canvas
- canvas 旋轉角度不需要累加Canvas
- HTML5 Canvas ( 矩形的繪製 ) rect, strokeRect, fillRectHTMLCanvas
- canvas矩形拖拽效果Canvas
- canvas繪製圓角矩形程式碼例項Canvas
- svg矩形圍繞自身中心旋轉效果SVG
- canvas旋轉太極圖效果Canvas
- canvas透明度的矩形效果Canvas
- canvas具有漸變效果的矩形Canvas
- canvas繪製卡通人臉形象效果Canvas
- canvas繪製多個圓圈效果Canvas
- canvas繪製網格射線效果Canvas
- Flutter2.0 繪製旋轉太空人+蛛網效果Flutter
- canvas學習筆記-繪製矩形及路徑(一)Canvas筆記
- 原來 Canvas 也能直接繪製圓角矩形了Canvas
- canvas繪製矩形並填充顏色程式碼例項Canvas
- HTML5利用canvas繪製矩形程式碼例項HTMLCanvas
- 使用 HTML5 Canvas 繪製的水滴效果HTMLCanvas
- canvas實現的旋轉太極圖效果Canvas
- canvas繪製經典星空連線效果Canvas
- canvas繪製太陽系運動效果Canvas
- canvas繪製北斗七星效果Canvas
- canvas繪製圓環效果程式碼例項Canvas
- SVG <rect> 繪製矩形SVG
- canvas繪製帶有漸變效果的直線Canvas
- SVG矩形旋轉動畫SVG動畫