 |
|
|  |
ÀÚ¹Ù½ºÅ©¸³Æ® ¿¬½À ¿¹Á¦ - ·£´ýÇÏ°Ô ¿òÁ÷ÀÌ´Â ÅؽºÆ® ¸¸µé±â |
|
|
 |
8³â Àü |
<script>
//·£´ýÇÑ Á¤¼ö »ý¼º
function nextRandomInteger(limit) {
return Math.round(Math.random() * limit);
}
//·£´ýÇÑ ¾ËÆĺª ¸®ÅÏ
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function randomAlphabet(){
return alphabet.charAt(nextRandomInteger(25));
}
//¾ç¼ö¿Í À½¼öÀÇ ·£´ýÇÑ ¼Óµµ »ý¼º
function randomSpeed(maxSpeed){
return Math.random() * maxSpeed - Math.random() * maxSpeed;
}
</script>
<script>
//Moving TextÀÇ »ý¼ºÀÚ ÇÔ¼ö
var canvasWidth = 700;
var canvasHeight = 400;
function MovingText(){
this.x = nextRandomInteger(canvasWidth);
this.y = nextRandomInteger(canvasHeight);
this.vx = randomSpeed(10);
this.vy = randomSpeed(10);
//¹®¼°´Ã¼ »ý¼º
this.body = document.createElement('h1');
this.body.innerHTML = randomAlphabet();
this.body.style.position = 'absolute';
//¹®¼°´Ã¼¸¦ document.body¿¡ Ãß°¡
document.body.appendChild(this.body);
}
MovingText.prototype.move = function(){
//¹üÀ§°Ë»ç
if(this.x < 0 || this.x > canvasWidth) {this.vx *= -1;}
if(this.y < 0 || this.y > canvasHeight) {this.vy *= -1;}
//À̵¿
this.x += this.vx;
this.y += this.vy;
//ȸ鿡 À̵¿Ç¥½Ã
this.body.style.left = this.x + 'px';
this.body.style.top = this.y + 'px';
};
</script>
<script>
window.onload = function(){
var movingTexts = [];
for(var i = 0; i<100; i++){
movingTexts.push(new MovingText());
}
setInterval(function(){
for(var i in movingTexts){
movingTexts[i].move();
}
}, 1000/60);
};
</script> |
|
̵̧ : 312 |
̵̧
¸ñ·Ï
|
|
|  |
|