descriptions somewhere on terrain gen?

john’s example is great, but with no real description of the generate sequences and use of noise, they’re daunting.

i’m wondering if there is prior art somewhere that would provide me some help?


@john let me add that i read a lot of other folks’ code, and much of it is pretty terrible. in contrast, yours is a delight to read: your skill is obvious. very good contributions! thanks!

@RonJeffries Come on Ron, give everyone a break. The people writing code here aren’t getting paid to do it. Most of them haven’t had that much experience writing code either. The ones that do have experience, myself included, write code in a matter of minutes to give examples to those asking questions, yourself included. So yes, a lot of the code here is terrible. But it gets the job done which is the whole point of this forum. Just giving you a rough time, and yes a lot of the code is terrible, mostly mine.

@RonJeffries - what have you got in mind? There are several examples of terrain generation in the forum. In the early days built on meshes. Now we’ve got Craft you can find a couple of simple examples from @dave1707 with tiling.

I’d like to know how to display a portion of a mesh and scroll it infinitely.

Also there are some examples for generating terrain height maps.

Are you talking voxel terrains here or something like the textured sphere @John’s Craft example.

voxel. i’ll look for some simpler examples i guess.

didn’t find much that hit me just right, but got some ideas from searching here.

i was really looking for some background info on noise-controlled terrain, to get the drift. john’s stuff is great, but takes a lot of teasing and decoding to grok.


Hi @RonJeffries this is the blog post that I based my terrain generation on:

This shows how it works in 2D. My terrain is a bit more complicated (rivers, trees, etc) but it should give you an idea of how to get started. The noise system I use is also based on the same thing.


@RonJeffries Heres an example using Craft and perlin noise. If you zoom in, it looks like a very dense city. You can increase the value of waterLevel to raise the water to cut down on the number of buildings.


function setup()
    assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
    scene = craft.scene(),vec3(200,50,0), 300, 0, 10000)
    scene.sun.rotation = quat.eulerAngles(25, 125, 0)
    scene.ambientColor = color(127, 127, 127, 255)       
    scene.voxels.coordinates = vec3(200,0,200)      
    for x=1,val,step do
        for z=1,val,step do  
            scene.voxels:box(x*m//1,0,z*m//1, x*m//1,y*10//1,z*m//1)

function update(dt)

function draw()

function blockSet()    
    dirtgrass = scene.voxels.blocks:new("DirtGrass")
    dirtgrass.setTexture(ALL, "Blocks:Dirt Grass")
    water = scene.voxels.blocks:new("Water")
    water.setTexture(ALL, "Blocks:Water")

@dave1707 All the code I’ve seen here is good, and John’s is the best. I review other people’s code as part of the courses and training I do, and it is that code I’m referring to as not very good. Code written by professional programmers, working for high pay, for corporations, and it doesn’t begin to measure up to what I see here. And John’s is notably good.

I’m sorry that I didn’t make clear that I wasn’t talking about any code I’ve seen here. I should add that I’ve always found your examples to be quite clear. John’s big examples are huge and quite well structured. I’d be proud to write anything that clear, and wish I knew anywhere near what you and other contributors here know.

Again, I’m sorry for giving the wrong impression.

And thanks for that example, I’ll try it as soon as I’m back on an iPad. Particularly kind of you since you though I had just dissed you. Again, I apologize for expressing myself so poorly!

Yes, needed to charge the iPad before tomorrow, so ran your little thing. Saved me writing something very similar tomorrow, I can move directly to whatever’s next. Except I’ll probably write it anyway because I’m weird that way.

The articles John pointed to handed me a few concepts that helped me understand much of what’s going on with the combiners and such. Plus the articles are interesting in their own right. Some of them make clear what amazing things people are doing in the GPUs.

I come from the era where we drew stuff on the face of an oscilloscope … it was a big deal to get a machine that had a little graphics language to drive the beam around :slight_smile:

Thanks again!

Here’s a question tho: why 0.42? and what does scene.voxels.coordinates do?



@RonJeffries I never thought you dissed me, I was just kidding you. I guess I wasn’t clear myself. As to the .42, it was just a number I picked. When working with perlin noise, you have to stay away from all integer x,y,z values, those always return 0. I was just picking a step value to stay away from hitting an integer.

ah :slight_smile: ok good, i hate to ever offend anyone unintentionally :slight_smile:
hmm and why doesn’t that loop draw a square instead of a circular disk?

@Simeon i noticed that Codea crashes if I use an octaves value of 0 or greater than 30 with perlin noise. There’s nothing in the docs that give a limit for octaves. Just wondering if other things will crash Codea with noise. I don’t know what’s easier, updating the docs to put limits on everything or modify Codea not to crash.

Hmm it definitely shouldn’t crash. Good catch, I’ll note this down and try to see what’s going on with those values

fiddled a bunch and still not clear on why @dave1707 's program draws a disc instead of a square … guessing this morning that there is a default voxels.radius set? when voxels.coordinates is used, does that affect what’s drawn, and if so, in what way?

i feel I’m missing a manual somewhere. :slight_smile:



@RonJeffries - I think it’s just using Perlin Noise to get a curve to define the shape and applying two sets of cubes - one as a flat plain with zero y and one with the actual box structure - they only differ in the y2 max coordinate for the definition.

I assume val at 200 is the box size.

I’d need to play around with it a bit more to be sure - but iPad on charge at the moment.

@RonJeffries From what I understand about the terrain stuff is the terrain is a circle or sphere based on the size you specify with voxels:resize. If you say resize(1,1,1) then the terrain area is 16x, 128y, 16z. If you say resize(5,1,5) then it’s 80x, 128y, 80z. The voxels.coordinates(x,y,z) places the center of the terrain at those coordinates. Not sure why it’s a circle (sphere) instead of a cube. I’m kind of playing with this stuff now, so I’m not 100% sure about what I’m saying. As for the prelim noise, at any x,y,z position you get some value. Think of a football field. Each point on the field gives some value. In my example I use that value to calculate a height (y) that I make the cubes at the x,0,z coordinates. So you get a lumpy area on the terrain that makes it look like a dense city.