function generate_posdir(current_particle, index) {
    //test to see if the particle is out of the canvas
    if (current_particle.x_pos >= win_width || current_particle.y_pos > win_height || current_particle.x_pos < 0 || current_particle.y_pos < 0) {
        //randomizing x and y positions
        rand_x = Math.floor(Math.random() * win_width);
        rand_y = Math.floor(Math.random() * win_height);

        x_dir = rand_range[Math.floor(Math.random() * 2)];
        y_dir = rand_range[Math.floor(Math.random()* 2)];

        //test like before to make sure no particles are stationary
        switch (x_dir) {
            case 0:
                y_dir = second_range[Math.floor(Math.random() * 2)];
                break;
        }
        switch (y_dir) {
            case 0:
                x_dir = second_range[Math.floor(Math.random() * 2)];
                break;
        }

        //setting the positions and directions with the given index
        particle_array[index].x_pos = rand_x;
        particle_array[index].y_pos = rand_y;
        
        particle_array[index].init_x_dir = x_dir;
        particle_array[index].init_y_dir = y_dir;
        ctx.arc(rand_x,rand_y, 2, 0, Math.PI*2, true);
    }
    else {
        //if the particle is not out of bounds, move it like normal
        ctx.arc(particle_array[index].x_pos, particle_array[index].y_pos, 2, 0, Math.PI*2, true);
    }
}
//function responsible for randomly relocating particles if they travel out of bounds
function responsible for randomly relocating particles if they travel out of bounds
function responsible for randomly relocating particles if they travel out of bounds
function generate_posdir(current_particle, index) {
    if (current_particle.x_pos >= win_width || current_particle.y_pos > win_height || current_particle.x_pos < 0 || current_particle.y_pos < 0) {
        rand_x = Math.floor(Math.random() * win_width);
        rand_y = Math.floor(Math.random() * win_height);
        x_dir = rand_range[Math.floor(Math.random() * 2)];
        y_dir = rand_range[Math.floor(Math.random()* 2)];
        switch (x_dir) {
            case 0:
                y_dir = second_range[Math.floor(Math.random() * 2)];
                break;
        }
        switch (y_dir) {
            case 0:
                x_dir = second_range[Math.floor(Math.random() * 2)];
                break;
        }
        particle_array[index].x_pos = rand_x;
        particle_array[index].y_pos = rand_y;
        particle_array[index].init_x_dir = x_dir;
        particle_array[index].init_y_dir = y_dir;
        ctx.arc(rand_x,rand_y, 2, 0, Math.PI*2, true);
    }
    else {
        ctx.arc(particle_array[index].x_pos, particle_array[index].y_pos, 2, 0, Math.PI*2, true);
    }
}
function generate_posdir ( current_particle , index ) { if ( current_particle . x_pos >= win_width || current_particle . y_pos > win_height || current_particle . x_pos < 0 || current_particle . y_pos < 0 ) { rand_x = Math . floor ( Math . random ( ) * win_width ) ; rand_y = Math . floor ( Math . random ( ) * win_height ) ; x_dir = rand_range [ Math . floor ( Math . random ( ) * 2 ) ] ; y_dir = rand_range [ Math . floor ( Math . random ( ) * 2 ) ] ; switch ( x_dir ) { case 0 : y_dir = second_range [ Math . floor ( Math . random ( ) * 2 ) ] ; break ; } switch ( y_dir ) { case 0 : x_dir = second_range [ Math . floor ( Math . random ( ) * 2 ) ] ; break ; } particle_array [ index ] . x_pos = rand_x ; particle_array [ index ] . y_pos = rand_y ; particle_array [ index ] . init_x_dir = x_dir ; particle_array [ index ] . init_y_dir = y_dir ; ctx . arc ( rand_x , rand_y , 2 , 0 , Math . PI * 2 , true ) ; } else { ctx . arc ( particle_array [ index ] . x_pos , particle_array [ index ] . y_pos , 2 , 0 , Math . PI * 2 , true ) ; } }
function responsible for randomly relocating particles if they travel out of bounds
function responsible for randomly relocating particles if they travel out of bounds
//test to see if the particle is out of the canvas //randomizing x and y positions //test like before to make sure no particles are stationary //setting the positions and directions with the given index //if the particle is not out of bounds, move it like normal