濮阳杆衣贸易有限公司

主頁 > 知識庫 > html5彈跳球示例代碼

html5彈跳球示例代碼

熱門標(biāo)簽:400開頭的電話好申請不 地圖標(biāo)注柱狀圖 智能芯電話機(jī)器人 百度地圖標(biāo)注為什么總是封號 咸陽穩(wěn)定外呼系統(tǒng)軟件 怎么做百度地圖標(biāo)注 臨海地圖標(biāo)注app 小朱地圖標(biāo)注 四川移動電銷外呼客戶管理系統(tǒng)
 

復(fù)制代碼
代碼如下:

<html>
<head>
<meta charset=utf-8>
<title>跳跳球</title>
<script>
//box
var box_x=0;
var box_y=0;
var box_width=300;
var box_height=300;
//注意:定位球采用球的中心
var ball_x=10;
var ball_y=10;
var ball_radius=10;
var ball_vx=5;
var ball_vy=3;
var box_bound_left=box_x+ball_radius;
var box_bound_right=box_x+box_width-ball_radius;
var box_bound_top=box_y+ball_radius;
var box_bound_bottom=box_y+box_height-ball_radius;
//ball
//context
var ctx;
function init()
{
ctx=document.getElementById('canvas').getContext('2d');
ctx.lineWidth=ball_radius;
ctx.fillStyle="rgb(200,0,50)";
move_ball();
setInterval(move_ball,100);//note
}
function move_ball()
{
ctx.clearRect(box_x,box_y,box_width,box_height);
move_and_check();
ctx.beginPath();
ctx.arc(ball_x,ball_y,ball_radius,0,Math.PI*2,true);
ctx.fill();
ctx.strokeRect(box_x,box_y,box_width,box_height);
}
function move_and_check()
{
var cur_ball_x=ball_x+ball_vx;
var cur_ball_y=ball_y+ball_vy;
if(cur_ball_x<box_bound_left)
{
ball_vx=-ball_vx;
cur_ball_x=box_bound_left;
}
if(cur_ball_x>box_bound_right)
{
ball_vx=-ball_vx;
cur_ball_x=box_bound_right;
}
if(cur_ball_y<box_bound_top)
{
ball_vy=-ball_vy;
cur_ball_y=box_bound_top;
}
if(cur_ball_y>box_bound_bottom)
{
ball_vy=-ball_vy;
cur_ball_y=box_bound_bottom;
}
ball_x=cur_ball_x;
ball_y=cur_ball_y;
}
</script>
</head>
<body onLoad="init()">
<canvas id="canvas" width="400" height="400"/>
</body>
</html>

標(biāo)簽:黃石 南平 平頂山 陜西 山南 公主嶺 黃石

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《html5彈跳球示例代碼》,本文關(guān)鍵詞  html5,彈跳,球,示例,代碼,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《html5彈跳球示例代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于html5彈跳球示例代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    白朗县| 宜川县| 巴青县| 平遥县| 林西县| 北辰区| 福海县| 正安县| 岳阳市| 集贤县| 博客| 东兰县| 杨浦区| 台中市| 蓝田县| 漯河市| 格尔木市| 望奎县| 淮北市| 江永县| 南部县| 和田县| 辽中县| 临安市| 龙胜| 莒南县| 宿松县| 泗阳县| 娄烦县| 彭水| 新化县| 大洼县| 鄂伦春自治旗| 漳平市| 沐川县| 阜新市| 利川市| 呼图壁县| 大兴区| 繁峙县| 宝应县|