doublesmooth_noise(int x, int y) { // 计算角落、边和中心的平均噪声值 double corners = (noise(x - 1, y - 1) + noise(x + 1, y - 1) + noise(x - 1, y + 1) + noise(x + 1, y + 1)) / 16; double sides = (noise(x - 1, y) + noise(x + 1, y) + noise(x, y - 1) + noise(x, y + 1)) / 8; double center = noise(x, y) / 4; // 返回平滑噪声值 return corners + sides + center;
插值公式
线性插值
1 2 3 4 5 6 7 8 9 10 11
//在两个值 a 和 b 之间进行插值,插值的程度由参数 x 控制 doubleinterpolate(double a, double b, double x) { // 计算插值权重 double ft = x * 3.1415927;//映射范围在 [0, 1] 的 x 值到一个角度范围内 double f = (1 - cos(ft)) * 0.5; //当 x 接近 0 或 1 时,f 的值趋近于 0,而当 x 接近 0.5 时,f 的值趋近于 1