If you think the Android project 4est listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.wordsaretoys.rise.pattern;
/*fromwww.java2s.com*//**
* classes and interfaces that generalize pattern generation
*/publicclass Pattern {
/*
* interfaces for real-valued functions
*/publicinterface F1F {
publicfloat get(float x);
}
publicinterface F2F {
publicfloat get(float x, float y);
}
publicinterface F3F {
publicfloat get(float x, float y, float z);
}
/*
* interfaces for integer-valued functions
*/publicinterface I1F {
publicfloat get(int x);
}
publicinterface I2F {
publicfloat get(int x, int y);
}
publicinterface I3F {
publicfloat get(int x, int y, int z);
}
publicinterface I2I {
publicint get(int x, int y);
}
/**
* cosine interpolation between two points
*/publicstaticfloat cerp(float y0, float y1, float mu) {
float m2 = (float)(1 - Math.cos(mu * Math.PI)) * 0.5f;
return (1 - m2) * y0 + m2 * y1;
}
/**
* cosine interpolation of I2F function
*/publicstaticfloat ipolate(I2F f, float x, float y) {
int ix = (int)Math.floor(x);
float fx = x - ix;
if (fx < 0) {
fx += 1;
}
int iy = (int)Math.floor(y);
float fy = y - iy;
if (fy < 0) {
fy += 1;
}
float s0 = f.get(ix, iy);
float s1 = f.get(ix + 1, iy);
float s2 = f.get(ix, iy + 1);
float s3 = f.get(ix + 1, iy + 1);
float s01 = cerp(s0, s1, fx);
float s23 = cerp(s2, s3, fx);
return cerp(s01, s23, fy);
}
}