<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

        如何用html5canvas實現(xiàn)勻速運動

        來源:懂視網(wǎng) 責(zé)編:小采 時間:2020-11-27 20:12:17
        文檔

        如何用html5canvas實現(xiàn)勻速運動

        如何用html5canvas實現(xiàn)勻速運動:勻速運動:指的是物體在一條直線上運動,并且物體在任何相等時間間隔內(nèi)通過的位移都是相等的。其實就是勻速直線運動,它的特點是加速度為0,從定義可知,在任何相等的時間間隔內(nèi),速度大小和方向是相同的。<head> <meta charset='u
        推薦度:
        導(dǎo)讀如何用html5canvas實現(xiàn)勻速運動:勻速運動:指的是物體在一條直線上運動,并且物體在任何相等時間間隔內(nèi)通過的位移都是相等的。其實就是勻速直線運動,它的特點是加速度為0,從定義可知,在任何相等的時間間隔內(nèi),速度大小和方向是相同的。<head> <meta charset='u

        勻速運動:指的是物體在一條直線上運動,并且物體在任何相等時間間隔內(nèi)通過的位移都是相等的。其實就是勻速直線運動,它的特點是加速度為0,從定義可知,在任何相等的時間間隔內(nèi),速度大小和方向是相同的。

        <head>
         <meta charset='utf-8' />
         <style>
         #canvas {
         border: 1px dashed #aaa;
         }
         </style>
         <script>
         window.onload = function () {
         var oCanvas = document.querySelector("#canvas"),
         oGc = oCanvas.getContext('2d'),
         width = oCanvas.width, height = oCanvas.height,
         x = 0;
         function drawBall( x, y, cxt ){
         cxt.fillStyle = '#09f';
         cxt.beginPath();
         cxt.arc( x, y, 20, 0, 2 * Math.PI );
         cxt.closePath();
         cxt.fill();
         }
         ( function linear(){
         oGc.clearRect( 0, 0, width, height );
         drawBall( x, height / 2, oGc );
         x += 2;
         console.log( x );
         requestAnimationFrame( linear );
         } )();
         }
         </script>
        </head>
        <body>
         <canvas id="canvas" width="1200" height="600"></canvas>
        </body>

        上述實例讓一個半徑20px的小球 從x=0, y=canvas高度的一半,以每幀2px的速度向右勻速運動.

        我們可以把小球封裝成一個對象:

        ball.js文件:

        function Ball( x, y, r, color ){
         this.x = x || 0;
         this.y = y || 0;
         this.radius = r || 20;
         this.color = color || '#09f';
        }
        Ball.prototype = {
         constructor : Ball,
         stroke : function( cxt ){
         cxt.strokeStyle = this.color;
         cxt.beginPath();
         cxt.arc( this.x, this.y, this.radius, 0, 2 * Math.PI );
         cxt.closePath();
         cxt.stroke();
         },
         fill : function( cxt ){
         cxt.fillStyle = this.color;
         cxt.beginPath();
         cxt.arc( this.x, this.y, this.radius, 0, 2 * Math.PI );
         cxt.closePath();
         cxt.fill();
         }
        }

        該小球?qū)ο螅梢远ㄖ莆恢冒霃胶皖伾С謨煞N渲染方式(描邊和填充)

        <head>
         <meta charset='utf-8' />
         <style>
         #canvas {
         border: 1px dashed #aaa;
         }
         </style>
         <script src="./ball.js"></script>
         <script>
         window.onload = function () {
         var oCanvas = document.querySelector("#canvas"),
         oGc = oCanvas.getContext('2d'),
         width = oCanvas.width, height = oCanvas.height,
         ball = new Ball( 0, height / 2 );
         (function linear() {
         oGc.clearRect(0, 0, width, height);
         ball.fill( oGc );
         ball.x += 2;
         requestAnimationFrame(linear);
         })();
         }
         </script>
        </head>
        
        <body>
         <canvas id="canvas" width="1200" height="600"></canvas>
        </body>

        斜線勻速運動:

        <head>
         <meta charset='utf-8' />
         <style>
         #canvas {
         border: 1px dashed #aaa;
         }
         </style>
         <script src="./ball.js"></script>
         <script>
         window.onload = function () {
         var oCanvas = document.querySelector("#canvas"),
         oGc = oCanvas.getContext('2d'),
         width = oCanvas.width, height = oCanvas.height,
         ball = new Ball( 0, height );
         (function linear() {
         oGc.clearRect(0, 0, width, height);
         ball.fill( oGc );
         ball.x += 2;
         ball.y -= 1;
         requestAnimationFrame(linear);
         })();
         }
         </script>
        </head>
        
        <body>
         <canvas id="canvas" width="1200" height="600"></canvas>
        </body>

        任意方向的勻速運動(速度分解)

        <head>
         <meta charset='utf-8' />
         <style>
         #canvas {
         border: 1px dashed #aaa;
         }
         </style>
         <script src="./ball.js"></script>
         <script>
         window.onload = function () {
         var oCanvas = document.querySelector("#canvas"),
         oGc = oCanvas.getContext('2d'),
         width = oCanvas.width, height = oCanvas.height,
         ball = new Ball( 0, 0 ),
         speed = 5,
         vx = speed * Math.cos( 10 * Math.PI / 180 ),
         vy = speed * Math.sin( 10 * Math.PI / 180 );
         
         (function linear() {
         oGc.clearRect(0, 0, width, height);
         ball.fill( oGc );
         ball.x += vx;
         ball.y += vy;
         requestAnimationFrame(linear);
         })();
         }
         </script>
        </head>
        <body>
         <canvas id="canvas" width="1200" height="600"></canvas>
        </body>

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        如何用html5canvas實現(xiàn)勻速運動

        如何用html5canvas實現(xiàn)勻速運動:勻速運動:指的是物體在一條直線上運動,并且物體在任何相等時間間隔內(nèi)通過的位移都是相等的。其實就是勻速直線運動,它的特點是加速度為0,從定義可知,在任何相等的時間間隔內(nèi),速度大小和方向是相同的。<head> <meta charset='u
        推薦度:
        標(biāo)簽: 運動 實現(xiàn) html5
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲日韩中文在线精品第一| 亚洲AV无码国产精品麻豆天美| 香蕉视频免费在线播放| 亚洲成a人片在线观看日本| 精品国产无限资源免费观看| 毛片亚洲AV无码精品国产午夜| 久久久久久a亚洲欧洲aⅴ| 91麻豆最新在线人成免费观看| 免费精品国产自产拍在线观看| 亚洲αv在线精品糸列| 午夜精品在线免费观看| 在线观看免费黄色网址| 亚洲欧美日韩久久精品| 久久久久无码精品亚洲日韩 | 亚洲美女激情视频| 免费观看理论片毛片| 亚洲一区二区精品视频| 亚洲自偷自偷在线成人网站传媒| 日韩亚洲精品福利| 精品一区二区三区无码免费视频| 免费va人成视频网站全| 三根一起会坏掉的好痛免费三级全黄的视频在线观看 | 久久综合国产乱子伦精品免费| 久久精品国产亚洲77777| 国产高清免费视频| 国产亚洲精品第一综合| 国产午夜亚洲不卡| 中文字幕免费视频| 日日摸日日碰夜夜爽亚洲| 亚洲综合精品网站在线观看| 人妻丰满熟妇无码区免费| 亚洲国产日韩综合久久精品| 亚洲国产小视频精品久久久三级| 国产综合免费精品久久久| 亚洲的天堂av无码| 国产a不卡片精品免费观看| 国产成人久久AV免费| 亚洲中文无码永久免| 色噜噜亚洲精品中文字幕| 国产一卡2卡3卡4卡无卡免费视频| 免费人成又黄又爽的视频在线电影|