int main() { float scale = 400.f; float offset_x = 5.9f; float offset_y = 5.1f; float offset_z = 0.05f; float lacunarity = 1.99f; float persistance = 0.5f; Img img; while (!img.is_closed()) { Measure measure; measure.start(); const SimplexNoise simplex(0.1f/scale, 0.5f, lacunarity, persistance); // Amplitude of 0.5 for the 1st octave : sum ~1.0f const int octaves = static_cast<int>(5 + std::log(scale)); // Estimate number of octaves needed for the current scale std::ostringstream title; title << "2D Simplex Perlin noise (" << octaves << " octaves)"; img.set_title(title.str().c_str()); for (int row = 0; row < img.height(); ++row) { const float y = static_cast<float>(row - img.height()/2 + offset_y*scale); for (int col = 0; col < img.width(); ++col) { const float x = static_cast<float>(col - img.width()/2 + offset_x*scale); // TODO(SRombauts): Add 'erosion' with simple smoothing like exponential, and other 'modifiers' like in libnoise // Generate "biomes", ie smooth geographic variation in frequency & amplitude, // and add smaller details, summing the noise values for the coordinate const float noise = simplex.fractal(octaves, x, y) + offset_z; const color3f color = ramp(noise); // convert to color img.draw_point(col, row, (float*)&color); } } img.display(); const double diff_ms = measure.get(); std::cout << std::fixed << diff_ms << "ms\n"; img.user(scale, offset_x, offset_y, offset_z, lacunarity, persistance); } return 0; }