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
- canvas 旋轉角度不需要累加Canvas
- HTML5 Canvas ( 矩形的繪製 ) rect, strokeRect, fillRectHTMLCanvas
- canvas繪製圓角矩形程式碼例項Canvas
- canvas學習筆記-繪製矩形及路徑(一)Canvas筆記
- 原來 Canvas 也能直接繪製圓角矩形了Canvas
- canvas繪製矩形並填充顏色程式碼例項Canvas
- HTML5利用canvas繪製矩形程式碼例項HTMLCanvas
- SVG <rect> 繪製矩形SVG
- SVG矩形旋轉動畫SVG動畫
- CSS3滑鼠懸浮元素旋轉一定角度CSSS3
- CSS3實現的div元素旋轉一定角度效果CSSS3
- SVG 繪製圓角矩形SVG
- canvas 繪製扇形Canvas
- canvas 繪製文字Canvas
- canvas繪製動畫的技巧Canvas動畫
- canvas 繪製線條Canvas
- canvas 繪製圓形Canvas
- canvas繪製流星效果Canvas
- canvas繪製直線Canvas
- JavaScript拖動滑鼠繪製矩形方框JavaScript
- canvas繪製不重合的圓Canvas
- Canvas 繪製雷達圖Canvas
- canvas 繪製立體圓環Canvas
- canvas 繪製文字詳解Canvas
- canvas 繪製雙線技巧Canvas
- canvas繪製風車效果Canvas
- canvas繪製笑臉表情Canvas
- canvas繪製太陽系Canvas