void PerlinNoise_Impl::create_noise2d(PerlinNoise_PixelWriter &writer, float start_x, float end_x, float start_y, float end_y) { float size_x = end_x - start_x; float size_y = end_y - start_y; float fheight = (float) height; float fwidth = (float) width; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float result = 0.0f; float current_amplitude = amplitude; float value_x = start_x + (((float) x) * size_x) / fwidth; float value_y = start_y + (((float) y) * size_y) / fheight; for( int i=0; i<octaves; i++ ) { result += current_amplitude * noise_2d(value_x, value_y); value_x *= 2.0f; value_y *= 2.0f; current_amplitude *= 0.5f; } writer.write_pixel(result); } writer.line_end(); } }
inline float smoothnoise_2d(float fx, float fy) { int x, y; x = fx, y = fy; float V1=noise_2d(x, y); float V2=noise_2d(x+1,y); float V3=noise_2d(x, y+1); float V4=noise_2d(x+1,y+1); float I1=interpolate(V1, V2, fx-int(fx)); float I2=interpolate(V3, V4, fx-int(fx)); float I3=interpolate(I1, I2, fy-int(fy)); return I3; }