lindsay
lindsay

Reputation: 972

Simplex noise reference to array

EDIT: I have been adjusting the sliders on the Simplex noise constructor. I have used more softer floating point numbers and have seen reduced numbers of bars. Possible solution?

{ frequency: 0.001, amplitude: 0.010, persistence: 0.50, octaves: 10 }

I'm working with Simplex noise to generate better pseudo random noise. I'm trying to create a basic map generator and I was hoping to use the Simplex noise generated to relate to a predefined array of textures. I am using the algorithm as interpreted from joshforisha to select a Simplex number scaled to the length of the array.

I've created a simplified version here. You might need to refresh the code a couple of times before you get it, but you should see repeating "un-simplex" style lines punctuating the Simplex noise.

My understanding of the situation is that the random number returned isn't being mapped the length of the array or it's skipping too many numbers, but I'm not sure.

Here is how the noise selection is being obtained from the array. I have omitted references to other defined code to keep this example as brief as I can.

var noiseGen = new FastSimplexNoise({
    /** use simplex noise constructor **/
    amplitude: 0.015,
    frequency: 0.015,
    octaves: 3,
    max: text.length /** set reference to length of textures **/,
    min: 0
});

/** iterate over canvas width **/
for (var i = 0; i < width; i++) {

    /** iterate over canvas height **/
    for (var j = 0; j < height; j++) {

       /** create noise point **/
       var n = noiseGen.in2D(i, j);

       /** make noise a whole number for use as index look up **/   
       var h = parseInt(n);

       /** get texture from array **/
       var t = text[h];

       /** paint **/
       ctx.fillStyle = t.hexidec;
       ctx.fillRect(i * scale, j * scale, scale, scale);
    }
 }

Upvotes: 0

Views: 292

Answers (1)

lindsay
lindsay

Reputation: 972

Answering my own question here. I believe that I had an issue with my noise algorithm. I have been tweaking how the squares are projected and distributed and it seems that this issue has been fixed. Thanks for anyone who set time aside to think about the issue.

Upvotes: 0

Related Questions