Ching Chang Chung
سه شنبه 18 شهریور 1393, 19:58 عصر
سلام
من یه کد پیداکردم که نحوه کار کردنش برام سواله اگه میتونید بگیدچه جوری کار میکنه ممنون میشم
<html><body onload = "step()">
<script type="text/javascript">
var NUM = 30;
var i = 0;
var a = new Array();
var b = new Array();
var pos_x = new Array();
var pos_y = new Array();
for(i = 1;i <= NUM;i++){
a[i] = Math.random() * 10 - 5;
b[i] = Math.random() * 10 - 5;
pos_x[i] = Math.random() * 300 + 100;
pos_y[i] = Math.random() * 200 + 130;
}
var shape = new Array();
for (i = 1;i <= NUM;i++){
shape[i] = new Image();
creat_img(shape[i],"http://s1.picofile.com/file/7205237525/Shape.png");
move(shape[i],pos_x[i],pos_y[i]);
}
var border_1_up = new Image();
creat_img(border_1_up,"http://s2.picofile.com/file/7205237311/border_1.png");
move(border_1_up,20,100);
var border_1_down = new Image();
creat_img(border_1_down,"http://s2.picofile.com/file/7205237311/border_1.png");
move(border_1_down,20,435);
var border_2_left = new Image();
creat_img(border_2_left,"http://s2.picofile.com/file/7205237418/border_2.png");
move(border_2_left,20,100);
var border_2_right = new Image();
creat_img(border_2_right,"http://s2.picofile.com/file/7205237418/border_2.png");
move(border_2_right,505,100);
function step(){
for(i = 1;i <= NUM;i++){
if(pos_x[i] < 27)a[i] *= -1;
if(pos_y[i] < 107)b[i] *= -1;
if(pos_x[i] > 453)a[i] *= -1;
if(pos_y[i] > 383)b[i] *= -1;
pos_x[i] += a[i];
pos_y[i] += b[i];
move(shape[i],pos_x[i],pos_y[i])
}
setTimeout("step()",20);
}
function creat_img(x,x_src){
x.setAttribute("src", x_src);
x.style.position = "absolute";
document.body.appendChild(x);
}
function move(obj,x,y){
obj.style.left = x + "px";
obj.style.top = y + "px";
}
</script>
</body>
</html>
من یه کد پیداکردم که نحوه کار کردنش برام سواله اگه میتونید بگیدچه جوری کار میکنه ممنون میشم
<html><body onload = "step()">
<script type="text/javascript">
var NUM = 30;
var i = 0;
var a = new Array();
var b = new Array();
var pos_x = new Array();
var pos_y = new Array();
for(i = 1;i <= NUM;i++){
a[i] = Math.random() * 10 - 5;
b[i] = Math.random() * 10 - 5;
pos_x[i] = Math.random() * 300 + 100;
pos_y[i] = Math.random() * 200 + 130;
}
var shape = new Array();
for (i = 1;i <= NUM;i++){
shape[i] = new Image();
creat_img(shape[i],"http://s1.picofile.com/file/7205237525/Shape.png");
move(shape[i],pos_x[i],pos_y[i]);
}
var border_1_up = new Image();
creat_img(border_1_up,"http://s2.picofile.com/file/7205237311/border_1.png");
move(border_1_up,20,100);
var border_1_down = new Image();
creat_img(border_1_down,"http://s2.picofile.com/file/7205237311/border_1.png");
move(border_1_down,20,435);
var border_2_left = new Image();
creat_img(border_2_left,"http://s2.picofile.com/file/7205237418/border_2.png");
move(border_2_left,20,100);
var border_2_right = new Image();
creat_img(border_2_right,"http://s2.picofile.com/file/7205237418/border_2.png");
move(border_2_right,505,100);
function step(){
for(i = 1;i <= NUM;i++){
if(pos_x[i] < 27)a[i] *= -1;
if(pos_y[i] < 107)b[i] *= -1;
if(pos_x[i] > 453)a[i] *= -1;
if(pos_y[i] > 383)b[i] *= -1;
pos_x[i] += a[i];
pos_y[i] += b[i];
move(shape[i],pos_x[i],pos_y[i])
}
setTimeout("step()",20);
}
function creat_img(x,x_src){
x.setAttribute("src", x_src);
x.style.position = "absolute";
document.body.appendChild(x);
}
function move(obj,x,y){
obj.style.left = x + "px";
obj.style.top = y + "px";
}
</script>
</body>
</html>