canvas小球拋物線運動
分享一段程式碼例項,它利用canvas實現了小球的拋射效果。
簡單的拋物線效果,程式碼例項如下:
[HTML] 純文字檢視 複製程式碼執行程式碼<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style> html,body,canvas{ width:100vw; height:100vh; background:#000000; overflow:hidden; } </style> <script> setTimeout(() => { let canvas = document.querySelector('canvas'); let context = canvas.getContext('2d'); canvas.width = canvas.offsetWidth; canvas.height = canvas.offsetHeight; let pointer = { x: 0, y: canvas.height / 2 }; let render = () => { context.clearRect(0, 0, canvas.width, canvas.height); context.fillStyle = "green"; context.beginPath(); context.arc(pointer.x ,pointer.y, 100, 0, 2 * Math.PI, false); context.fill(); }; let vx = 7; let vy = -7; let run; ( run= () => { pointer.x += vx; // 位置恆定變化 vy += 0.1; // 速度恆定變化 pointer.y += vy; if (pointer.x > canvas.width || pointer.y > canvas.height) { pointer.x = 0; pointer.y = canvas.height / 2; vy = -7; } render(); requestAnimationFrame(run) })(); }, 500); </script> </head> <body> <canvas></canvas> </body> </html>
相關文章
- js小球拋物線效果程式碼例項JS
- canvas小球碰壁隨機運動Canvas隨機
- canvas繪製拋物線程式碼例項Canvas線程
- canvas小球擺動效果Canvas
- js模擬拋物運動和慣性運動JS
- canvas小球落地彈動效果Canvas
- 小程式拋物線動畫動畫
- canvas小球碰壁效果Canvas
- canvas小球亂撞Canvas
- JavaScript模擬拋物運動的程式碼實現JavaScript
- JS 實現拋物線動畫JS動畫
- js隨機運動小球效果JS隨機
- 原生JS實現拋物線動畫以及動態模糊效果JS動畫
- 奇妙的canvas:彈跳小球Canvas
- canvas 四處亂竄的小球Canvas
- canvas繪製小球漸隱漸現Canvas
- PPT中平拋運動的實現
- canvas 實現光線沿不規則路徑運動Canvas
- canvas小球旋轉loadding載入效果Canvas
- canvas小球隨機漂浮碰撞程式碼例項Canvas隨機
- unity3D 兩點拋物線模擬炮彈Unity3D
- canvas水平勻速運動效果Canvas
- JavaScript模擬拋物效果JavaScript
- javascript 多物體運動JavaScript
- canvas實現的彈力小球效果程式碼例項Canvas
- canvas繪製太陽系運動效果Canvas
- HTML5中canvas實現小球擊打小方塊遊戲HTMLCanvas遊戲
- canvas實現的隨機生成漂浮小球程式碼例項Canvas隨機
- canvas繪製滑鼠懸浮可以變大的立體小球Canvas
- canvas實現的小球四壁碰撞效果程式碼例項Canvas
- 原生JavaScript運動功能系列(四):多物體多值鏈式運動JavaScript
- WebAssembly Demo之Canvas中隨機運動圓球WebCanvas隨機
- html5 canvas 實現光線沿不規則路徑運動例項程式碼HTMLCanvas
- css3小球上下移動效果CSSS3
- canvas 虛線矩形Canvas
- canvas基礎之動態線條---致敬windows98CanvasWindows
- canvas 繪製線條Canvas
- canvas繪製直線Canvas