用户:查看:2 回复:4 评论:2 创建时间:2021-08-06T18:54:10
版权声明:YDS尹子
说了只是改良版本,所以基本算法是不变的(改也不知道咋改())
改良是指随机性:感觉尹子原版本是固定地形,有点单调()。
建议做代码随机生成地形的循环图使用,固定的地形图看不见效果():
var seaLevel=1;
var xzZoom=Math.round(Math.random()*(1-40) + 40) ;//重要的都在这里,下面都是照搬的尹子的算法()
var yZoom=Math.round(Math.random()*(1-6) + 6) ;
var exZ1=Math.round(Math.random()*(1-3) + 3) ;
var base=Math.round(Math.random()*(80-100) + 100) ;
var a=Math.round(Math.random()*(5-10) + 10);
var b=Math.round(Math.random()*(10-30) + 30);
(async function(){
for(let i=0;i<127;i++){
var xh=Math.pow(Math.sin(i/xzZoom),a)*yZoom*exZ1-i/b;
for(let j=0;j<127;j++){
var zh=Math.pow(Math.sin(j/xzZoom),a)*yZoom*exZ1;
voxels.setVoxel(i,xh+zh+base,j,"sand");
for(let k=0;k<xh+zh+base-1;k++){
voxels.setVoxel(i,k,j,"sand");
}
}
await sleep(20);
}
world.say("仙人掌建造中");
for(let i=0;i<127;i++){
for(let j=0;j<127;j++){
for(let k=0;k<100;k++){
if(voxels.getVoxel(i,k,j)==voxels.id("sand")&&voxels.getVoxel(i,k+1,j)==0){
if(Math.random()*500<=1){
voxels.setVoxel(i,k+1,j,"green_leaf");
voxels.setVoxel(i,k+2,j,"green_leaf");
voxels.setVoxel(i,k+3,j,"green_leaf");
}
}
}
}
await sleep(10);
}
})();
图差不多,去试试就知道了~
把函数算法改(试)了一下(圈),感觉这样还不错👇

var seaLevel=1;
var xzZoom=Math.round(Math.random()*(20-40) + 40) ;
var yZoom=Math.round(Math.random()*(2-5) + 5) ;
var exZ1=Math.round(Math.random()*(0-3) + 3) ;
var base=Math.round(Math.random()*(30-40) + 40) ;
var a=Math.round(Math.random()*(5-10) + 10);
var b=Math.round(Math.random()*(10-30) + 30);
(async function(){
for(let i=0;i<127;i++){
var xh=Math.pow(Math.tanh(i/xzZoom),a)*yZoom*exZ1-i/b;
for(let j=0;j<127;j++){
var zh=Math.pow(Math.tanh(j/xzZoom),a)*yZoom*exZ1;
voxels.setVoxel(i,xh+zh+base,j,"sand");
for(let k=0;k<xh+zh+base-1;k++){
voxels.setVoxel(i,k,j,"sand");
}
}
await sleep(20);
}
world.say("仙人掌建造中");
for(let i=0;i<127;i++){
for(let j=0;j<127;j++){
for(let k=0;k<100;k++){
if(voxels.getVoxel(i,k,j)==voxels.id("sand")&&voxels.getVoxel(i,k+1,j)==0){
if(Math.random()*500<=1){
voxels.setVoxel(i,k+1,j,"green_leaf");
voxels.setVoxel(i,k+2,j,"green_leaf");
voxels.setVoxel(i,k+3,j,"green_leaf");
}
}
}
}
await sleep(10);
}
})();
由于本人为了地形刚刚接触函数,真的是没搞懂啥意思()
点赞0
评论