<html>
<head>
<title>飘动小球</title>
<style>
form {
background-color: yellow;
}
</style>
<script>
var ctx;
var g=2;
var balls=[];
function Ball(bx,by,rad,color){
this.bx = bx;
this.by = by;
this.rad = rad;
this.fillStyle = color;
this.draw = drawball;
}
function drawball(){
ctx.fillStyle = this.fillStyle;
ctx.beginPath();
ctx.arc(this.bx,this.by,this.rad,0,Math.PI*2,true);
ctx.fill();
}
function init(){
ctx = document.getElementById('canvas').getContext('2d');
setInterval(creat,100);
}
function drawall(){
ctx.clearRect(0,0,600,600);
var i;
for (i=0;i<balls.length;i++){
balls[i].draw();
}
ctx.strokeRect(0,0,600,600);
}
function creat(){
var col = 'rgb('+ Math.floor(Math.random()*256) + ','+
HTML5实现随机生成小球并向上移动
最新推荐文章于 2021-06-03 09:35:58 发布