Skip to content
The Chat Archive
sonar-reasoning-pro-high LMArena Search Arena 24K

code a single p5.js script that simulates water

  1. User

    code a single p5.js script that simulates water

  2. Assistant

    P5.js Water Simulation

    Here's a complete P5.js script that simulates water with a realistic ripple effect. This simulation uses a physical model where disturbances in the water propagate outward as waves:

    // Water ripple simulation
    let cols, rows;
    let current; // Current water state
    let previous; // Previous water state
    let damping = 0.97; // Energy loss (lower = more loss)
    
    function setup() {
      createCanvas(windowWidth, windowHeight);
      pixelDensity(1); // For consistent behavior across displays
      
      cols = width;
      rows = height;
      
      // Create 2D arrays for water height
      current = new Array(cols).fill(0).map(() => new Array(rows).fill(0));
      previous = new Array(cols).fill(0).map(() => new Array(rows).fill(0));
    }
    
    function mouseDragged() {
      // Create splash where mouse is dragged
      if (mouseX > 1 && mouseX < cols - 2 && mouseY > 1 && mouseY < rows - 2) {
        previous[mouseX][mouseY] = 500; // Add energy at mouse position
      }
    }
    
    function mousePressed() {
      // Create splash where mouse is clicked
      if (mouseX > 1 && mouseX < cols -
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.