ccc 正态分布

时间:2024-03-28 16:05:26


cc.Class({
extends: cc.Component, properties: {
prefab:
{
default:null,
type:cc.Prefab
},
root:
{
default:null,
type:cc.Node
}
}, // use this for initialization
onLoad: function () {
for(var i=0;i<100;i++)
{
var mullers=this.getMuller()
console.log(mullers[0])
console.log(mullers[1])
//初始化prefab
var mark=cc.instantiate(this.prefab);
mark.parent=this.root
mark.position=cc.p(mullers[0]*480,mullers[1]*320)
} //初始化prefab
var mark=cc.instantiate(this.prefab);
mark.parent=this.root
mark.position=cc.p(0,0)
}, getMuller:function()
{
var a=Math.random()
var b=Math.random()
var r=Math.sqrt(-2*Math.log(a))
var z1=r*Math.cos(2*Math.PI*b)
var z2=r*Math.sin(2*Math.PI*b)
var mullers=new Array(z1,z2)
return [z1,z2]
} // called every frame, uncomment this function to activate update callback
// update: function (dt) { // },
});