用户:
全能代码师查看:5 回复:5 评论:5 创建时间:2021-08-07T22:32:51
/*world的长宽高*/
let worldx = 128;
let worldy = 128;
let worldz = 128;
let hillnum = 50;/*山丘数量,可以自定义*/
(async function () {
for (let x = 0; x < worldx; x++) {
for (let z = 0; z < worldz; z++) {
for (let y = 0; y < worldy; y++) {
voxels.setVoxel(x, y, z, 0);
};
};
};
await sleep(3000);
for (let x = 0; x < worldx; x++) {
for (let z = 0; z < worldz; z++) {
for (let y = 0; y < 9; y++) {
voxels.setVoxel(x, y, z, 'grass');
};
};
};
await sleep(3000);
for (let i = 0; i < hillnum + 1; i++) {
var x = Math.random() * worldx;
var y = 9;
var z = Math.random() * worldz;
var weight = 5 + Math.random() * 15;
for (let j = 0; j < weight + 1; j++) {
cylinder('grass', x, y, z, weight - j, 1);
if (Math.random() < 0.2) {
cylinder('grass', x, y, z, weight - j, 2);
y++;
}
y++
};
};
})();
function cylinder(vox, cx, cy, cz, radius, height) {
var xend = cx + radius;
var yend = cy + height;
var zend = cz + radius;
for (let x = cx - radius; x <= xend; x++) {
for (let z = cz - radius; z <= zend; z++) {
let dx = x - cx;
let dz = z - cz;
if (Math.round(Math.sqrt(dx * dx + dz * dz)) <= radius) {
for (let y = cy; y < yend; y++) {
if (Math.random() < 0.95) {
voxels.setVoxel(x, y, z, vox);
}
};
};
};
};
};
