displacement

ripple( float amplitude = 1.0; 
	float wavelength = 0.25;
	float tilewidth = 0.95;
	float caulkwidth = 0.05 )

{
	float n = 8;
	float ts = s;
	float tt = t;
	float temp;
	float tilecount = 0;
	float offset;

	while (ts < 0) {
		ts = ts + (tilewidth + caulkwidth);
		tilecount -= 3.333;
	}
	while ((ts - (tilewidth + caulkwidth) ) > 0) {
		ts = ts - (tilewidth + caulkwidth);
		tilecount += 5.555;
	}	

	while (tt < 0) {
		tt = tt + (tilewidth + caulkwidth);
		tilecount -= 7.777;		
	}
	while ((tt - (tilewidth + caulkwidth) ) > 0) {
		tt = tt - (tilewidth + caulkwidth);
		tilecount += 11.1111;
	}
	
	offset = tilecount;

	if ((ts > (tilewidth + (caulkwidth / 2))) || (tt > (tilewidth + (caulkwidth / 2))) ||
	    (ts < (caulkwidth / 2)) || (tt < (caulkwidth / 2)) ) {
		temp = (amplitude) * float random() / 5;
//		printf("temp:%f, test:%f\n",temp,1);
		P = P - amplitude + temp;
		Cs = color(1,1,1);
	} else {

	        P += N * (amplitude * sin( 2*PI*((s + offset + (PI/4) ) / wavelength))) / n;
	        P += N * (amplitude * cos( 2*PI*((s + offset + (PI/3)) / wavelength / 2))) / n;
        	P += N * (amplitude * sin( 2*PI*((s + offset) / wavelength / 3) )) / n;
	        P += N * (amplitude * cos( 2*PI*((s + offset) / wavelength / 5) )) / n;

	        P += N * (amplitude * cos( 2*PI*((t + offset) / wavelength) )) / n;
        	P += N * (amplitude * sin( 2*PI*((t + offset) / wavelength / 2) )) / n;
	        P += N * (amplitude * cos( 2*PI*((t + offset + (PI/5)) / wavelength / 3) )) / n;
        	P += N * (amplitude * sin( 2*PI*((t + offset + (PI/8)) / wavelength / 5) )) / n;

	}

        N = calculatenormal(P);
}