• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專(zhuān)題視頻專(zhuān)題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專(zhuān)題1關(guān)鍵字專(zhuān)題50關(guān)鍵字專(zhuān)題500關(guān)鍵字專(zhuā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)鍵字專(zhuān)題關(guān)鍵字專(zhuān)題tag2tag3文章專(zhuān)題文章專(zhuān)題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專(zhuān)題3
    問(wèn)答文章1 問(wèn)答文章501 問(wèn)答文章1001 問(wèn)答文章1501 問(wèn)答文章2001 問(wèn)答文章2501 問(wèn)答文章3001 問(wèn)答文章3501 問(wèn)答文章4001 問(wèn)答文章4501 問(wèn)答文章5001 問(wèn)答文章5501 問(wèn)答文章6001 問(wèn)答文章6501 問(wèn)答文章7001 問(wèn)答文章7501 問(wèn)答文章8001 問(wèn)答文章8501 問(wèn)答文章9001 問(wèn)答文章9501
    當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

    如何用html5canvas實(shí)現(xiàn)勻速運(yùn)動(dòng)

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

    如何用html5canvas實(shí)現(xiàn)勻速運(yùn)動(dòng)

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

    勻速運(yùn)動(dòng):指的是物體在一條直線上運(yùn)動(dòng),并且物體在任何相等時(shí)間間隔內(nèi)通過(guò)的位移都是相等的。其實(shí)就是勻速直線運(yùn)動(dòng),它的特點(diǎn)是加速度為0,從定義可知,在任何相等的時(shí)間間隔內(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>

    上述實(shí)例讓一個(gè)半徑20px的小球 從x=0, y=canvas高度的一半,以每幀2px的速度向右勻速運(yùn)動(dòng).

    我們可以把小球封裝成一個(gè)對(duì)象:

    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>

    斜線勻速運(yùn)動(dòng):

    <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>

    任意方向的勻速運(yùn)動(dòng)(速度分解)

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

    文檔

    如何用html5canvas實(shí)現(xiàn)勻速運(yùn)動(dòng)

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

    最新推薦

    猜你喜歡

    熱門(mén)推薦

    專(zhuān)題
    Top
    主站蜘蛛池模板: 国产精品视频免费一区二区| 精品国产AⅤ一区二区三区4区| 91精品国产综合久久四虎久久无码一级 | 老司机67194精品线观看| 国产精品videossex白浆| 国产精品一区二区久久不卡| 亚洲一区无码精品色| 国产精品自在欧美一区| 久久国产精品99精品国产987| 久久99国内精品自在现线| 正在播放国产精品每日更新| 人人妻人人澡人人爽精品欧美 | 国产精品自在线拍国产电影| 国产精品久久自在自线观看| 久久精品亚洲一区二区三区浴池| 欧美日韩精品在线观看| 国产亚洲精品国看不卡| 亚洲国产精品久久久久婷婷软件| 国产精品亚洲片夜色在线| 国产精品白丝AV网站| 奇米精品视频一区二区三区| 亚洲精品国偷自产在线| 亚洲精品线路一在线观看| 日韩精品成人亚洲专区| 久久亚洲国产精品五月天婷| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 日本Aⅴ大伊香蕉精品视频 | laowang在线精品视频| 97久久综合精品久久久综合| 99精品国产在热久久| 国产原创精品视频| 香蕉国产精品频视| 四虎在线精品视频一二区| 亚洲无删减国产精品一区| 亚洲精品私拍国产福利在线| 999国产精品色在线播放| 久久久国产精品福利免费| 日本精品中文字幕| 国产99视频精品免费视频76| 成人国产精品一区二区视频| 国产精品va久久久久久久|