canvas translate()、scale()和rotate()方法程式碼例項
本章節分享一段程式碼例項,它演示了標題中三個方法的用法。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼執行程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <script> function draw() { var canvas = document.getElementById("canvas"); if (canvas == null) { return false; } var context = canvas.getContext("2d"); context.fillStyle = "#eeeefe"; context.fillRect(0, 0, 400, 300); //圖形繪製 context.translate(200, 50); //左移動 200,下移動50 context.fillStyle = "rgba(255,0,0,0.5)"; for (var i = 0; i < 100; i++) { context.translate(25, 25); context.scale(0.95, 0.95);//縮小 context.rotate(Math.PI / 10); context.fillRect(0, 0, 100, 50); } } window.onload = function () { draw() } </script> </head> <body> <canvas id="canvas" width="400" height="300"></canvas> </body> </html>
相關文章
- Canvas之translate、scale、rotate、skew方法講解!Canvas
- 使用js從element的matrix推導transform的scale、rotate 和 translate引數JSORM
- Qt 從 QTransform 逆向解出 Translate/Scale/Rotate(平移/縮放/旋轉)分析QTORM
- canvas刮刮樂程式碼例項Canvas
- canvas畫圖程式碼例項Canvas
- canvas小遊戲程式碼例項Canvas遊戲
- canvas火焰效果程式碼例項Canvas
- CSS屬性transform之旋轉:rotate,縮放:scale,傾斜:skew,移動:translateCSSORM
- canvas繪製扇形程式碼例項Canvas
- canvas繪製星星程式碼例項Canvas
- canvas字母雨效果程式碼例項Canvas
- canvas載入效果程式碼例項Canvas
- canvas 繪製雞蛋程式碼例項Canvas
- canvas縮放div程式碼例項Canvas
- canvas擺動效果程式碼例項Canvas
- canvas rotate()Canvas
- canvas translate()Canvas
- canvas translateCanvas
- canvas scale()Canvas
- canvas水位進度效果程式碼例項Canvas
- canvas原型鐘錶效果程式碼例項Canvas原型
- canvas氣泡上浮效果程式碼例項Canvas
- canvas寫字板功能程式碼例項Canvas
- canvas繪製網格程式碼例項Canvas
- canvas貪吃蛇遊戲程式碼例項Canvas遊戲
- canvas實現的刮刮樂程式碼例項Canvas
- canvas田字格效果程式碼例項Canvas
- canvas徑向漸變程式碼例項Canvas
- canvas繪製笑臉程式碼例項Canvas
- canvas繪製圓環效果程式碼例項Canvas
- canvas線性漸變程式碼例項Canvas
- canvas螞蟻線效果程式碼例項Canvas
- STL原始碼之rotate函式結合圖和例項分析原始碼函式
- CSS3 translate導致字型模糊的例項程式碼CSSS3
- canvas繪製米字旗程式碼例項Canvas
- canvas模擬彈幕效果程式碼例項Canvas
- canvas繪製箭頭效果程式碼例項Canvas
- canvas繪製拋物線程式碼例項Canvas線程