
Lv.1
Everything happens for a reason.
签名:https://box3.codemao.cn/u/YDSyinzi
在 【岛3-API教程3!】用方块检测,做一片刀山火海🌋 中回复
吉吉喵怎么不把我的地形代码宣传一下
/*
main conditions under here.
copyright YDS���� 2020,All rights reserved.
*/
var grid={
x:127,
y:127,
z:127,
sx:70,
sy:70,
sz:70
};
var posY=7;
var sealevel=15;
var seed="";
var grassPos=[];
var pointer=0;
var mtD={
num:10,
h:7,
w:6,
hs:10,
ws:5,
};
async function mt(position,yZoom,xzZoom){
for(let tri=-xzZoom*3.14;tri<=xzZoom*3.14;tri+=0.05){
for(let tri2=-xzZoom*3.14;tri2<=xzZoom*3.14;tri2+=0.05){
var xh=Math.cos(tri/xzZoom)*yZoom;
var zh=Math.cos(tri2/xzZoom)*yZoom;
voxels.setVoxel(position.x+tri,position.y+xh+zh+0.5,position.z+tri2,"grass");
grassPos[pointer]=position;
pointer++;
}
await sleep(0.3);
}
};
(async function(){
for(let i=1;i<=mtD.num;i++){
var position={x:Math.random()*(grid.x-grid.sx)+grid.sx,y:posY,z:Math.random()*(grid.z-grid.sz)+grid.sz};
var height=mtD.h+Math.random()*mtD.hs;
var width=mtD.w+Math.random()*mtD.ws;
await mt(position,height,width);
world.say("开始生成山"+Math.round(i/mtD.num*1000)/10+"%");
}
for(let i=grid.sx;i<grid.x;i++){
for(let j=grid.sz;j<grid.z;j++){
for(let k=0;k<grid.y;k++){
if(voxels.getVoxel(i,k,j)==voxels.id("grass")){
if(voxels.getVoxel(i,k+1,j)==voxels.id("grass")){
voxels.setVoxel(i,k,j,"dirt");
}else if(voxels.getVoxel(i,k+1,j)==0){
for(let ii=position.y;ii<k;ii++){
voxels.setVoxel(i,ii,j,"dirt");
}
}
}
}
await sleep(1);
}
if(Math.round(i/0.126)/10%0.5==0){
world.say("处理中。。。"+Math.round(i/0.126)/10+"%");
}
}
world.say("开始生成水");
for(let i=grid.sx;i<grid.x;i++){
for(let j=grid.sz;j<grid.z;j++){
for(let k=0;k<sealevel;k++){
if(voxels.getVoxel(i,k,j)==voxels.id("grass")){
voxels.setVoxel(i,k,j,"dirt")
}else if(voxels.getVoxel(i,k,j)==0){
voxels.setVoxel(i,k,j,"water")
}
}
if(voxels.getVoxel(i,sealevel,j)==voxels.id("grass")){
voxels.setVoxel(i,sealevel,j,"sand")
}else if(voxels.getVoxel(i,sealevel,j)==0){
voxels.setVoxel(i,sealevel,j,"water")
}
}
}
})()
/*
extreme conditions under here.
copyright YDS���� 2020,All rights reserved.
*/
//ice
var snowL=60;
(async function(){
world.say("开始生成雪线");
for(let i=0;i<127;i++){
for(let j=0;j<127;j++){
for(let k=snowL;k<127;k++){
if(voxels.getVoxel(i,k,j)==voxels.id("grass")&&Math.random()*1.3<1){
voxels.setVoxel(i,k,j,"snow")
}else if(voxels.getVoxel(i,k,j)==voxels.id("dirt")&&Math.random()*1.5<1){
voxels.setVoxel(i,k,j,"snow")
}
}
}
}
})()
//tree
function tree(x,y,z){
if(voxels.getVoxel(x,y,z)!=voxels.id("water")){
var rand=1;
for(let i=y+rand;i<y+4+rand;i++){
voxels.setVoxel(x,i,z,"acacia");
}
for(let i=3+rand;i<5+rand;i++){
for(let j=-2;j<3;j++){
for(let k=-2;k<3;k++){
voxels.setVoxel(x+j,y+i,z+k,"green_leaf");
}
}
}
for(let j=-1;j<2;j++){
for(let k=-1;k<2;k++){
voxels.setVoxel(x+j,y+5+rand,z+k,"green_leaf");
}
}
voxels.setVoxel(x-1,y+6+rand,z,"green_leaf");
voxels.setVoxel(x,y+6+rand,z,"green_leaf");
voxels.setVoxel(x+1,y+6+rand,z,"green_leaf");
voxels.setVoxel(x,y+6+rand,z-1,"green_leaf");
voxels.setVoxel(x,y+6+rand,z+1,"green_leaf");
}
};
(async function(){
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("grass")){
if(Math.random()*200<=1){
tree(i,k,j);
}
}
}
}
await sleep(10);
}
})();
//lamp
(async function(){
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("grass")&&voxels.getVoxel(i,k+1,j)==0){
if(Math.random()*200<=1){
voxels.setVoxel(i,k,j,"palace_lamp");
}
}
}
}
await sleep(10);
}
})();
//grass overFlow
var grid={
x:127,
y:127,
z:127
};
for(let i=0;i<grid.x;i++){
for(let j=0;j<grid.z;j++){
for(let k=0;k<grid.y;k++){
if(voxels.getVoxel(i,k,j)!=0){
if(voxels.getVoxel(i,k+1,j)!=0&&voxels.getVoxel(i,k,j)==voxels.id("grass")){
voxels.setVoxel(i,k,j,"dirt");
}
}
}
}
}
//all chuLis
for(let i=0;i<127;i++){
for(let j=0;j<127;j++){
for(let k=0;k<127;k++){
if(voxels.getVoxel(i,k,j)==voxels.id("grass")){
if(voxels.getVoxel(i,k+1,j)!=0){
voxels.setVoxel(i,k,j,"dirt");
}else if(voxels.getVoxel(i,k+1,j)==0){
for(let ii=8;ii<k;ii++){
voxels.setVoxel(i,ii,j,"dirt");
}
}
}
}
}
}
//single mt
async function mt(position,yZoom,xzZoom){
for(let tri=-xzZoom*3.14;tri<=xzZoom*3.14;tri+=0.05){
for(let tri2=-xzZoom*3.14;tri2<=xzZoom*3.14;tri2+=0.05){
var xh=Math.cos(tri/xzZoom)*yZoom;
var zh=Math.cos(tri2/xzZoom)*yZoom;
voxels.setVoxel(position.x+tri,position.y+xh+zh+0.5,position.z+tri2,"grass");
}
await sleep(0.3);
}
};
(async function(){
var position={x:126,y:6,z:126};
var height=10;
var width=10;
await mt(position,height,width);
world.say("开始生成山"+Math.round(i/mtD.num*1000)/10+"%");
})()
2020-11-06T20:13:30 点赞:0
在 [挖坟项目] 它又双叒叕回来了 中回复
shy看下我的作品——
https://shequ.codemao.cn/community/349783
https://shequ.codemao.cn/community/350135
2020-11-27T19:59:31 点赞:0
在 【box3】超级峡谷地形发布! 中回复
链接显示的出来那我就不再发一遍了
有任何问题请回复。
(美化)种树代码:
function tree(x,y,z){
if(voxels.getVoxel(x,y,z)!=voxels.id("water")){var rand=1;
for(let i=y+rand;i<y+4+rand;i++){voxels.setVoxel(x,i,z,"acacia");}
for(let i=3+rand;i<5+rand;i++){for(let j=-2;j<3;j++){for(let k=-2;k<3;k++){voxels.setVoxel(x+j,y+i,z+k,"green_leaf");}}}
for(let j=-1;j<2;j++){for(let k=-1;k<2;k++){voxels.setVoxel(x+j,y+5+rand,z+k,"green_leaf");}}
voxels.setVoxel(x-1,y+6+rand,z,"green_leaf");voxels.setVoxel(x,y+6+rand,z,"green_leaf");voxels.setVoxel(x+1,y+6+rand,z,"green_leaf");voxels.setVoxel(x,y+6+rand,z-1,"green_leaf");voxels.setVoxel(x,y+6+rand,z+1,"green_leaf");
}
};
(async function(){
for(let i=0;i<257;i++){
for(let j=0;j<257;j++){for(let k=0;k<50;k++){if(voxels.getVoxel(i,k,j)==voxels.id("grass")){if(Math.random()*150<=1){
tree(i,k,j);
}}}}
await sleep(10);
}
})();2020-12-19T09:28:18 点赞:0
在 【box3】突破:柏林噪音地图生成及代码! 中回复
第二版本代码:
function tree(x,y,z){
if(voxels.getVoxel(x,y,z)!=voxels.id("water")){var rand=1;
for(let i=y+rand;i<y+4+rand;i++){voxels.setVoxel(x,i,z,"acacia");}
for(let i=3+rand;i<5+rand;i++){for(let j=-2;j<3;j++){for(let k=-2;k<3;k++){voxels.setVoxel(x+j,y+i,z+k,"green_leaf");}}}
for(let j=-1;j<2;j++){for(let k=-1;k<2;k++){voxels.setVoxel(x+j,y+5+rand,z+k,"green_leaf");}}
voxels.setVoxel(x-1,y+6+rand,z,"green_leaf");voxels.setVoxel(x,y+6+rand,z,"green_leaf");voxels.setVoxel(x+1,y+6+rand,z,"green_leaf");voxels.setVoxel(x,y+6+rand,z-1,"green_leaf");voxels.setVoxel(x,y+6+rand,z+1,"green_leaf");
}
};
async function spawnTree(){
for(let i=0;i<257;i++){
for(let j=0;j<257;j++){for(let k=0;k<50;k++){if(voxels.getVoxel(i,k,j)==voxels.id("grass")){if(Math.random()*150<=1){
tree(i,k,j);
}}}}
await sleep(10);
}
}
var noise = {};
function Cor(x, y, z) {
this.x = x; this.y = y; this.z = z;
}
Cor.prototype.dot2 = function (x, y) {
return this.x * x + this.y * y;
};
Cor.prototype.dot3 = function (x, y, z) {
return this.x * x + this.y * y + this.z * z;
};
var Cor3 = [new Cor(1, 1, 0), new Cor(-1, 1, 0), new Cor(1, -1, 0), new Cor(-1, -1, 0),
new Cor(1, 0, 1), new Cor(-1, 0, 1), new Cor(1, 0, -1), new Cor(-1, 0, -1),
new Cor(0, 1, 1), new Cor(0, -1, 1), new Cor(0, 1, -1), new Cor(0, -1, -1)];
var p = [151, 160, 137, 91, 90, 15,
131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23,
190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33,
88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166,
77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244,
102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196,
135, 130, 116, 188, 159, 86, 1喵, 100, 109, 198, 173, 186, 3, 喵, 52, 217, 226, 250, 124, 123,
5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42,
223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9,
129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228,
251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107,
49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254,
138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180];
// var p=20;
// To remove the need for index wrapping, double the permutation table length
var perm = new Array(512);
var CorP = new Array(512);
// This isn't a very good seeding function, but it works ok. It supports 2^16
// different seed values. Write something better if you need more seeds.
noise.seed = function (seed) {
if (seed > 0 && seed < 1) {
// Scale the seed out
seed *= 65536;
}
seed = Math.floor(seed);
if (seed < 256) {
seed |= seed << 8;
}
for (var i = 0; i < 256; i++) {
var v;
if (i & 1) {
v = p[i] ^ (seed & 255);
// v = p^ (seed & 255);
} else {
v = p[i] ^ ((seed >> 8) & 255);
// v = p^ ((seed >> 8) & 255);
}
perm[i] = perm[i + 256] = v;
CorP[i] = CorP[i + 256] = Cor3[v % 12];
}
};
noise.seed(20);
// Skewing and unskewing factors for 2, 3, and 4 dimensions
var F2 = 0.5 * (Math.sqrt(3) - 1); var G2 = (3 - Math.sqrt(3)) / 6; var F3 = 1 / 3; var G3 = 1 / 6;
// ##### Perlin noise stuff
function fade(t) { return t * t * t * (t * (t * 6 - 15) + 10); }
function lerp(a, b, t) { return (1 - t) * a + t * b; }
// 3D Perlin Noise
noise.perlin3 = function (x, y, z) {
// Find unit grid cell containing point
var X = Math.floor(x), Y = Math.floor(y), Z = Math.floor(z);
// Get relative xyz coordinates of point within that cell
x = x - X; y = y - Y; z = z - Z;
// Wrap the integer cells at 255 (喵aller integer period can be introduced here)
X = X & 255; Y = Y & 255; Z = Z & 255;
// Calculate noise contributions from each of the eight corners
var n000 = CorP[X + perm[Y + perm[Z]]].dot3(x, y, z);
var n001 = CorP[X + perm[Y + perm[Z + 1]]].dot3(x, y, z - 1);
var n010 = CorP[X + perm[Y + 1 + perm[Z]]].dot3(x, y - 1, z);
var n011 = CorP[X + perm[Y + 1 + perm[Z + 1]]].dot3(x, y - 1, z - 1);
var n100 = CorP[X + 1 + perm[Y + perm[Z]]].dot3(x - 1, y, z);
var n101 = CorP[X + 1 + perm[Y + perm[Z + 1]]].dot3(x - 1, y, z - 1);
var n110 = CorP[X + 1 + perm[Y + 1 + perm[Z]]].dot3(x - 1, y - 1, z);
var n111 = CorP[X + 1 + perm[Y + 1 + perm[Z + 1]]].dot3(x - 1, y - 1, z - 1);
// Compute the fade curve value for x, y, z
var u = fade(x);
var v = fade(y);
var w = fade(z);
// Interpolate
return lerp(
lerp(
lerp(n000, n100, u),
lerp(n001, n101, u), w),
lerp(
lerp(n010, n110, u),
lerp(n011, n111, u), w),
v);
};
// var canvas = document.getElementsByTagName('canvas')[0];
var canvas = {};
canvas.width = 257;
canvas.height = 257;
// var image = ctx.createImageData(canvas.width, canvas.height);
// var data = image.data;
var height = Math.random() * 20;
var watl = 25;
var basic = 5;
async function drawFrame() {
var start = Date.now();
// Cache width and height values for the canvas.
var cWidth = canvas.width;
var cHeight = canvas.height;
var zoom = 20;
var max = -Infinity, min = Infinity;
var noisefn = noise.perlin3;
for (var x = 0; x < cWidth; x++) {
for (var y = 0; y < cHeight; y++) {
var value = noisefn(x / zoom, y / zoom, height);
value = (1 + value) * 1.1 * 28;
if (max < value) max = value;
if (min > value) min = value;
if (value - basic < watl) {
for (let i = 0; i < value - basic - 1; i++) { voxels.setVoxel(x, i, y, "dirt") }
for (let i = value - basic; i <= watl; i++) { voxels.setVoxel(x, i, y, "water") }
}
else {
// if (Math.round(value - basic) == watl||Math.round(value - basic) == watl-1) voxels.setVoxel(x, value - basic, y, "sand")
if (value - basic > watl) voxels.setVoxel(x, value - basic, y, "grass")
for (let i = 0; i < value - basic - 1; i++) { voxels.setVoxel(x, i, y, "dirt") }
}
}
if (x % 20 == 0)
await sleep(200);
world.say("terrain spawning..." + Math.round(x / cWidth * 1000) / 10 + "%")
}
spawnTree();
height += 0;
}
drawFrame();
2020-12-31T21:28:00 点赞:0