Perlin noise .noise(x,y) method

Hello, I’ve been playing around with the perlin noise generation for making height field maps for a game I’d like to make. I had been using perlinNoiseFill() to make a heightfield but the size is a bit of an issue :frowning:

I heard that it is possible to make it continuous if use the same object on the points you want. So I had a look at the .noise(x,y) method. This seems to be what I want but my real question is what do I do with the values I get? I get a number between -1 and 1 but I’m not sure where to go from there :confused: Am I meant to multiply it by something to make them numbers I can fill an image with (like perlinNoiseFill) or do they have some other purpose.

Thanks for the help :slight_smile:

EDIT: occasionally I get a value under -1 like -1.32103050487

Don’t worry I got it working now :slight_smile: I did this:

p = self.perlin.noise(x+self.offsetx,y+self.offsety)
if p >= 0:
    p*=127.5
    self.n.setRedVal(x,y,p)
    self.n.setGreenVal(x,y,p)
    self.n.setBlueVal(x,y,p)

I’m not sure if that’s the right way but it works ok.

By the way, if anyone wants to make connecting terrain chunks with the panda3d perlin noise, here is some of my code for doing it (it may not be the best way though :slight_smile: )

class FPS(object,DirectObject):
    name = -1
    chunkposx = 0
    chunkposy = 0
    chunksize = 1025
    chunks = []
    chunks1 = []
    offsetx = 0
    offsety = 0
    perlin = PerlinNoise2(500,500)

This is my function to make a chunk:

    def makeChunk(self):
        self.n = PNMImage(self.chunksize,self.chunksize)
        self.offsety -=self.chunksize
        for y in xrange(self.chunksize):
            for x in xrange(self.chunksize):
                p = self.perlin.noise(x+self.offsetx,y+self.offsety)
                if p >= 0:
                    p*=127.5
                    self.n.setRedVal(x,y,p)
                    self.n.setGreenVal(x,y,p)
                    self.n.setBlueVal(x,y,p)
        self.n.makeGrayscale()
        self.name+=1
        name1 = str(self.name)
        self.n.write(name1+".png")
        #GeoMipTerrain Stuff
        terrain = GeoMipTerrain(name1)
        terrain.setHeightfield(self.n)
        terrain.setBlockSize(128)
        terrain.setNear(256)
        terrain.setFar(512)
        terrain.setMinLevel(2)
        terrain.setFocalPoint(base.camera)
        root = terrain.getRoot()
        root.reparentTo(render)
        root.setSz(100)
        self.scaleZ = root.getSz()
        terrain.setAutoFlatten(GeoMipTerrain.AFMStrong)
        terrain.generate()
        ts = TextureStage("ts0")
        root.setTexture(ts,loader.loadTexture("test.png"))
        root.setLight(self.plnp)
        root.setShaderInput("light", self.plnp)
        root.setLight(self.alnp)
        root.setShaderAuto()
        root.setPos(self.chunkposx,self.chunkposy,0)
        self.chunks.append(terrain)
        self.chunks1.append(root)

To calculate when a new chunk is needed, I have not quite finished (at the moment it works in one direction)
I check to see if the player’s position is greater than half the length of the chunk and make a new if that is true.

Hope that helps, :slight_smile: I found the sources on perlin noise pretty confusing so hopefully someone will find this ^ useful.

EDIT: just remembered for some reason it should be chunks instead of self.chunks. (make them global in def init(self):slight_smile: because:

for i in self.chunks:

gives an error saying self is not defined. The same with self.chunks1