コード例 #1
0
float PerlinNoise(float x, float y, int width, int octaves, int seed, double period) {

	double a, b, value, freq, zone_x, zone_y;
	int s, box, num, step_x, step_y;
	float amplitude = period;
	int noisedata;

	freq = 1 / period;
	value = 0;

	for (s = 0; s<octaves; s++) {
		num = static_cast<int>(width*freq);
		step_x = static_cast<int>(x*freq);
		step_y = static_cast<int>(y*freq);
		zone_x = x*freq - step_x;
		zone_y = y*freq - step_y;
		box = step_x + step_y*num;
		noisedata = (box + seed);
		a = InterLinear(Noise(noisedata), Noise(noisedata + 1), zone_x);
		b = InterLinear(Noise(noisedata + num), Noise(noisedata + 1 + num), zone_x);
		value += InterLinear(a, b, zone_y)*amplitude;
		freq *= 4;
		amplitude /= 4;
	}
	return value;
}
コード例 #2
0
/*! \brief Returns the exact value if x is a multiple of dx, else interpolated value.
 *
 * Interpolation method depends on InterpolType input. \n
 * It is checked. Its expected values are TRU, LIN, CUB and LAG.
 *
 * \return
 * \f[ \left\{ \begin{array}{ll} 
 TruncVal(x) & \textrm{if } modulo(\frac{x-x_0}{dx},1) \approx 0 \\
 TruncVal(x) & \textrm{if } InterpolType = TRU \\
 InterLinear(x) & \textrm{if } InterpolType = LIN \\
 InterCubic(x) & \textrm{if } InterpolType = CUB \\
 InterLagrange(x, int(InterpUtilValue)) & \textrm{if } InterpolType =  LAG
  \end{array} \right.\f]
 */
double Serie2::gData(double x, INTERP InterpolType, double InterpUtilValue)
{
	//cout << "Serie2::gData :" << endl;
	//cout << "  fmod(xr,1.0) = " << fmod(xr,1.0) << endl;
	
	xr = (x-x0)/dx ;
	bin = MathUtils::ifloor(xr);
	xrbinE = true;
	//if(fmod((x-x0)/dx,1.0) < PRECISION){
		//cout << "  --> Tronque" << endl;
	if((xr-bin) < PRECISION){
		return(TruncVal(x));
	}else{
		switch(InterpolType){
			case TRU :
				return(TruncVal(x));
				break;
			case LIN :
				return(InterLinear(x));
				break;
			case CUB :
				return(InterCubic(x));
				break;
			case LAG :
				return(InterLagrange(x, int(InterpUtilValue)));
				break;
				//case SIN :
				//	return(InterSincTrunc(x, int(InterpUtilValue)));
				//	break;	
			default :
				throw invalid_argument("Serie2: No interpolation method !");
		}
	}
}