Here’s an updated version of some code I wrote previously. It’s a terrain generator, best viewed in landscape mode. Run the code to create a random terrain that shows water, grass, dirt, and snow. Tap the restart icon to create another random terrain. If you create some terrain that you think is interesting, you can tap the > icon to show the print area. That shows values that can be hard coded to recreate that terrain anytime you run with them. I have values that are commented out that I thought created an interesting view. Just uncomment the lines and run it. If you come across one that’s interesting, just post the values.
viewer.mode=FULLSCREEN
function setup()
assert(OrbitViewer, "Please include Cameras as a dependency")
scene = craft.scene()
v=scene.camera:add(OrbitViewer,vec3(275,100,100), 500, 0, 2000)
v.camera.farPlane=10000
v.rx,v.ry=50,-40
scene.voxels.blocks:addAssetPack("Blocks")
dirtgrass = scene.voxels.blocks:new("DirtGrass")
dirtgrass.setTexture(ALL, "Blocks:Dirt Grass")
water = scene.voxels.blocks:new("Water")
water.setTexture(ALL, "Blocks:Water")
snow = scene.voxels.blocks:new("Snow")
snow.setTexture(ALL, "Blocks:Snow")
grass = scene.voxels.blocks:new("Grass Top")
grass.setTexture(ALL, "Blocks:Grass Top")
scene.voxels.visibleRadius=40
scene.voxels:resize(vec3(30,1,30))
scene.voxels.coordinates = vec3(100,0,100)
offsetX=math.random(500)
offsetZ=math.random(500)
dirtLevel=math.random(70,90)
grassLevel=math.random(40,60)
waterLevel=math.random(5,15)
--offsetX=2
--offsetZ=156
--dirtLevel=70
--grassLevel=42
--waterLevel=7
output.clear()
print("offsetX "..offsetX)
print("offsetZ "..offsetZ)
print("dirtLevel "..dirtLevel)
print("grassLevel "..grassLevel)
print("waterLevel "..waterLevel)
val=400
m=1/val
h=craft.noise.perlin()
xx=0
for x=1,val do
xx=xx+m
zz=0
for z=1,val do
zz=zz+m
y=math.abs(h:getValue(xx+offsetX,0,zz+offsetZ))*150//1
if y>127 then
y=127-(y-127)
end
if y>=dirtLevel then
scene.voxels:fill("Snow")
scene.voxels:block(x,y,z)
elseif y>=grassLevel then
scene.voxels:fill("DirtGrass")
scene.voxels:block(x,y,z)
elseif y>=waterLevel then
scene.voxels:fill("Grass Top")
scene.voxels:block(x,y,z)
else
scene.voxels:fill("Water")
scene.voxels:block(x,waterLevel,z)
end
end
end
end
function update(dt)
scene:update(dt)
end
function draw()
update(DeltaTime)
scene:draw()
end