function draw() {
        /*
        This calculates the velocity of the mouse by getting the distance between the last coordinates and 
        the new ones. The coordinates will be further apart depending on how fast the mouse is moving.
        */
        var mouse_xv = mouse.x - mouse.px;
        var mouse_yv = mouse.y - mouse.py;
        
        //Loops through all of the columns
        for (i = 0; i < vec_cells.length; i++) {
            var cell_datas = vec_cells[i];

            //Loops through all of the rows
            for (j = 0; j < cell_datas.length; j++) {
                
                //References the current cell
                var cell_data = cell_datas[j];
                
                //If the mouse button is down, updates the cell velocity using the mouse velocity
                if (mouse.down) {
                    change_cell_velocity(cell_data, mouse_xv, mouse_yv, pen_size);
                }

                //This updates the pressure values for the cell.
                update_pressure(cell_data);
            }
        }
        
        /*
        This line clears the canvas. It needs to be cleared every time a new frame is drawn
        so the particles move. Otherwise, the particles would just look like long curvy lines.
        */
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        //This sets the color to draw with.
        ctx.strokeStyle = "#00FFFF";

        //This calls the function to update the particle positions.
        update_particle();

        /*
        This calls the function to update the cell velocity for every cell by looping through
        all of the rows and columns.
        */
        for (i = 0; i < vec_cells.length; i++) {
            var cell_datas = vec_cells[i];

            for (j = 0; j < cell_datas.length; j++) {
                var cell_data = cell_datas[j];

                update_velocity(cell_data);

            }
        }
        
        //This replaces the previous mouse coordinates values with the current ones for the next frame.
        mouse.px = mouse.x;
        mouse.py = mouse.y;

        //This requests the next animation frame which runs the draw() function again.
        requestAnimationFrame(draw);

    }
/*
    This is the main animation loop. It is run once from the init() function when the page is fully loaded and 
    uses RequestAnimationFrame to run itself again and again.
    */
This is the main animation loop. It is run once from the init() function when the page is fully loaded and
uses RequestAnimationFrame to run itself again and again.
This is the main animation loop . It is run once from the init () function when the page is fully loaded and uses RequestAnimationFrame to run itself again and again .
function draw() {
        var mouse_xv = mouse.x - mouse.px;
        var mouse_yv = mouse.y - mouse.py;
        for (i = 0; i < vec_cells.length; i++) {
            var cell_datas = vec_cells[i];
            for (j = 0; j < cell_datas.length; j++) {
                var cell_data = cell_datas[j];
                if (mouse.down) {
                    change_cell_velocity(cell_data, mouse_xv, mouse_yv, pen_size);
                }
                update_pressure(cell_data);
            }
        }
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        ctx.strokeStyle = "#00FFFF";
        update_particle();
        for (i = 0; i < vec_cells.length; i++) {
            var cell_datas = vec_cells[i];
            for (j = 0; j < cell_datas.length; j++) {
                var cell_data = cell_datas[j];
                update_velocity(cell_data);
            }
        }
        mouse.px = mouse.x;
        mouse.py = mouse.y;
        requestAnimationFrame(draw);
    }
function draw ( ) { var mouse_xv = mouse . x - mouse . px ; var mouse_yv = mouse . y - mouse . py ; for ( i = 0 ; i < vec_cells . length ; i ++ ) { var cell_datas = vec_cells [ i ] ; for ( j = 0 ; j < cell_datas . length ; j ++ ) { var cell_data = cell_datas [ j ] ; if ( mouse . down ) { change_cell_velocity ( cell_data , mouse_xv , mouse_yv , pen_size ) ; } update_pressure ( cell_data ) ; } } ctx . clearRect ( 0 , 0 , canvas . width , canvas . height ) ; ctx . strokeStyle = "#00FFFF" ; update_particle ( ) ; for ( i = 0 ; i < vec_cells . length ; i ++ ) { var cell_datas = vec_cells [ i ] ; for ( j = 0 ; j < cell_datas . length ; j ++ ) { var cell_data = cell_datas [ j ] ; update_velocity ( cell_data ) ; } } mouse . px = mouse . x ; mouse . py = mouse . y ; requestAnimationFrame ( draw ) ; }
This is the main animation loop.
This is the main animation loop .
/*
        This calculates the velocity of the mouse by getting the distance between the last coordinates and 
        the new ones. The coordinates will be further apart depending on how fast the mouse is moving.
        */ //Loops through all of the columns //Loops through all of the rows //References the current cell //If the mouse button is down, updates the cell velocity using the mouse velocity //This updates the pressure values for the cell. /*
        This line clears the canvas. It needs to be cleared every time a new frame is drawn
        so the particles move. Otherwise, the particles would just look like long curvy lines.
        */ //This sets the color to draw with. //This calls the function to update the particle positions. /*
        This calls the function to update the cell velocity for every cell by looping through
        all of the rows and columns.
        */ //This replaces the previous mouse coordinates values with the current ones for the next frame. //This requests the next animation frame which runs the draw() function again.