OpenSimplexNoise - Looping noise

I’ve made a class with the common implementation of sampling 2 maps and using the OpenSimplex eval 4D function.

This is especially useful for anyone looking for a terrain generator. A friend of mine asked me to help him with this, and I needed it for myself also.

public class OpenSimplexLoop {
	private OpenSimplexNoise noise;
	private int sizex, sizey;
	
	public OpenSimplexLoop(OpenSimplexNoise noise, int sizex, int sizey) {
		this.noise = noise;
		this.sizex = sizex;
		this.sizey = sizey;
	}
	
	public double loopedNoise(double radx, double rady){
		double s = (radx) / sizex;
		double t = (rady) / sizey;
		
		double x1 = -10, x2 = 10;
		double y1 = -10, y2 = 10;
		
		double dx = x2 - x1;
		double dy = y2 - y1;
		
		double x = x1 + Math.cos(s * 2 * Math.PI) * dx / (2 * Math.PI);
		double y = y1 + Math.cos(t * 2 * Math.PI) * dy / (2 * Math.PI);
		double z = x1 + Math.sin(s * 2 * Math.PI) * dx / (2 * Math.PI);
		double w = y1 + Math.sin(t * 2 * Math.PI) * dy / (2 * Math.PI);
		
		return noise.eval(x, y, z, w);
	}
}

Just plug in the size of your map in the constructor and then sample it within the bounds using [icode]loopedNoise(…)[/icode]

Some results

Here’s a 400x400 img with the seed 300

Here’s a 800x800 img with the seed 300 and the coordinates scaled by / 2 (making the noise algo extrapolate)

I based this off of this article also, the author talked about some of the scaling values in the comments if you read his code and are confused.
http://www.gamedev.net/blog/33/entry-2138456-seamless-noise/