#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
// Constants
const int GRID_SIZE = 20; // Size of the grid (GRID_SIZE x GRID_SIZE)
const double DAMPING_FACTOR = 0.98; // Damping factor for ripple effect
const double RIPPLE_STRENGTH = 10.0; // Initial strength of the ripple
const int RIPPLE_RADIUS = 5; // Radius of the ripple effect
const int NUM_STEPS = 30; // Number of simulation steps
// Function to initialize the grid
void initializeGrid(std::vector<std::vector<double>>& grid) {
for (int i = 0; i < GRID_SIZE; ++i) {
for (int j = 0; j < GRID_SIZE; ++j) {
grid[i][j] = 0.0;
}
}
}
// Function to create a ripple effect
void createRipple(std::vector<std::vector<double>>& grid, int centerX, int centerY, double strength) {
for (int i = 0; i < GRID_SIZE; ++i) {
for (int j = 0; j < GRID_SIZE; ++j) {
double distance = std::sqrt((i - centerX) * (i - centerX) + (j - centerY) * (j - centerY));
if (distance < RIPPLE_RADIUS) {
grid[i][j] += strength * (1.0 - distance / RIPPLE_RADIUS);
}
}
}
}
// Function to update the grid
void updateGrid(std::vector<std::vector<double>>& grid) {
std::vector<std::vector<double>> newGrid = grid;
for (int i = 1; i < GRID_SIZE - 1; ++i) {
for (int j = 1; j < GRID_SIZE - 1; ++j) {
newGrid[i][j] = (grid[i - 1][j] + grid[i + 1][j] + grid[i][j - 1] + grid[i][j + 1]) / 4.0;
newGrid[i][j] *= DAMPING_FACTOR;
}
}
grid = newGrid;
}
// Function to print the grid
void printGrid(const std::vector<std::vector<double>>& grid) {
for (const auto& row : grid) {
for (double value : row) {
std::cout << std::setw(6) << std::fixed << std::setprecision(2) << value << " ";
}
std::cout << "\n";
}
std::cout << "\n";
}
int main() {
// Create a grid for the simulation
std::vector<std::vector<double>> grid(GRID_SIZE, std::vector<double>(GRID_SIZE, 0.0));
// Initialize the grid
initializeGrid(grid);
// Create an initial ripple effect
createRipple(grid, GRID_SIZE / 2, GRID_SIZE / 2, RIPPLE_STRENGTH);
std::cout << "Initial Ripple Effect:\n";
printGrid(grid);
// Simulate the ripple effect over time
for (int step = 0; step < NUM_STEPS; ++step) {
updateGrid(grid);
std::cout << "Step " << step + 1 << ":\n";
printGrid(grid);
}
return 0;
}