Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A solution I figured out: Firstly, I generate 100,000,000 perlin noises and store them in an array. I sort it, and afterwards I can take every 10,000 value as a threshold for one per mille. Now I can hardcode these thresholds, so I've just an array with 1,000 floats for lookup at runtime.</p> <p>Advantages:</p> <p>It's <em>really</em> fast, as it's just one array access at runtime.</p> <p>Drawbacks:</p> <p>If you change the algorithm, you have to regenerate your threshold array. Secondly, the mean scales to about 10 per mille, making a 50% threshold either 49.5% or 50.5% (depending on whether you use &lt; or &lt;= comperator). Thirdly, the increased memory footprint (4kb with per mill precision). You can reduce it by using percent precision or a logarithmic precision scale.</p> <p>Generation code:</p> <pre><code>final PerlinNoiseGenerator perlin = new PerlinNoiseGenerator(new Random().nextInt()); final int size = 10000; //Size gets sqared, so it's actually 100,000,000 final float[] values = new float[size * size]; for (int x = 0; x &lt; size; x++) for (int y = 0; y &lt; size; y++) { final float value = perlin.noise2(x / 10f, y / 10f); values[x * size + y] = value; } System.out.println("Calculated"); Arrays.sort(values); System.out.println("Sorted"); final float[] steps = new float[1000]; steps[999] = 1; for (int i = 0; i &lt; 999; i++) steps[i] = values[size * size / 1000 * (i + 1)]; System.out.println("Calculated steps"); for (int i = 0; i &lt; 10; i++) { System.out.println(); for (int j = 0; j &lt; 100; j++) System.out.print(steps[i * 100 + j] + "f, "); //Output usuable for array initialization System.out.println(); System.out.println(); } </code></pre> <p>Lookup code:</p> <pre><code>public final static float[] perlinThresholds = new float[]{}; //Initialize it with the generated thresholds. public static float getThreshold(float percent) { return perlinThresholds[(int)(percent * 1000)]; } public static float getThreshold(int promill) { return perlinThresholds[promill]; } X </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload