Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.bretzel.challenge.thechallenge;
- import org.bukkit.util.noise.NoiseGenerator;
- import java.util.Random;
- public class DiamondNoise extends NoiseGenerator
- {
- private Random random;
- private int[][] DATA;
- public DiamondNoise()
- {
- this.random = new Random();
- int size = 512;
- DATA = new int[size][size];
- DATA[0][0] = random.nextInt(256);
- DATA[0][size - 1] = random.nextInt(256);
- DATA[size - 1][size - 1] = random.nextInt(256);
- DATA[size - 1][0] = random.nextInt(256);
- int i = size - 1;
- while (i > 1)
- {
- int id = i / 2;
- for (int x = id; x <= size; x += i)
- {
- for (int y = id; y <= size; y += i)
- {
- int moyenne = (DATA[x - id][y - id] +
- DATA[x - id][y + id] +
- DATA[x + id][y + id] +
- DATA[x + id][y - id]) / 4;
- DATA[x][y] = moyenne + random.nextInt(2 * id) + id;
- }
- }
- int decalage = 0;
- for (int x = 0; x <= size - 1; x += id)
- {
- if (x % i == 0)
- decalage = id;
- else decalage = 0;
- for (int y = decalage; y <= decalage; y++)
- {
- int somme = 0;
- int n = 0;
- if (x >= id)
- {
- somme = somme + DATA[x - id][y];
- n++;
- }
- if ((x + id) < size)
- {
- somme = somme + DATA[x + id][y];
- n++;
- }
- if (y >= id)
- {
- somme = (somme + DATA[x][y - id]);
- n++;
- }
- if ((y + id) < size)
- {
- somme = somme + DATA[x][y + id];
- n++;
- }
- DATA[x][y] = (somme / n + random.nextInt(2 * id) - id);
- }
- }
- i = id;
- }
- }
- @Override
- public double noise(double x, double y)
- {
- if (DATA.length <= 0)
- return 0;
- return DATA[(int) x][(int) y];
- }
- @Override
- public double noise(double x, double y, double z)
- {
- return noise(x, y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement