@Override public float noise(float x, float y) { float xMod = TeraMath.modulus(x, sampleRate); float yMod = TeraMath.modulus(y, sampleRate); float x0 = x - xMod; float x1 = x0 + sampleRate; float y0 = y - yMod; float y1 = y0 + sampleRate; float q00 = source.noise(x0 * zoom.x, y0 * zoom.y); float q10 = source.noise(x1 * zoom.x, y0 * zoom.y); float q01 = source.noise(x0 * zoom.x, y1 * zoom.y); float q11 = source.noise(x1 * zoom.x, y1 * zoom.y); return TeraMath.biLerp(q00, q10, q01, q11, xMod / sampleRate, yMod / sampleRate); }
private float[] getKeyValues(Rect2i fullRegion) { int xDim = fullRegion.size().x / sampleRate + 1; int yDim = fullRegion.size().y / sampleRate + 1; float[] fullData = new float[xDim * yDim]; for (int y = 0; y < yDim; y++) { for (int x = 0; x < xDim; x++) { int actualX = x * sampleRate + fullRegion.minX(); int actualY = y * sampleRate + fullRegion.minY(); fullData[x + y * xDim] = source.noise(zoom.x * actualX, zoom.y * actualY); } } return fullData; }
/** * Returns Fractional Brownian Motion at the given position. * * @param x Position on the x-axis * @param y Position on the y-axis * @return The noise value in the range [-getScale()..getScale()] */ @Override public float noise(float x, float y) { float result = 0.0f; float workingX = x; float workingY = y; for (int i = 0; i < getOctaves(); i++) { result += other.noise(workingX, workingY) * (float) getSpectralWeight(i); workingX *= (float) getLacunarity(); workingY *= (float) getLacunarity(); } return result; }