最近需要用到颜色随机的效果(类似于随机点名的那种叭)
color:rgb(x,y,z); (red,blue,green)
思路很简单:主要用到Math对象中的两个函数,
Math.random()获得随机数0~1,
以及Math.floor(),向下取整
function Color(){
this.r = Math.floor(Math.random()*255);
this.g = Math.floor(Math.random()*255);
this.b = Math.floor(Math.random()*255);
this.color = 'rgb('+ this.r +','+ this.g +','+ this.b')';
return this.color;
}