JSFiddle - React, Tailwind, and code Playground

by eddiemonge

JavaScript

var IAmDelay = function(arr, count) {
    
    // Stop when there are no more
    if ( arr.length < count ) {
        return;
    }





    if(arr[count].length > 0) {
        context.beginPath();
        // I want to delay the itteration of this loop for every "X" millisecs
        for(var j=0;j<path_array[i].length;j++) {
            var current_cords = path_array[i][j];
            draw_x = parseInt(current_cords.substr(0,current_cords.indexOf(',')),10);
            draw_y = parseInt(current_cords.substr(current_cords.indexOf(',')+1),10);

            if (j === 0) {
                context.moveTo(draw_x,draw_y);
            } else {
                context.lineTo(draw_x,draw_y);
                context.stroke();
            }
            
        }
        context.closePath();
    }






    setTimeout(function() {
        IAmDelay(arr, count+1);
    }, 2000);
};
IAmDelay(path_array, count);