var canvas = document.getElementById('planoDeFundo'); var context = canvas.getContext('2d'); var towerA = [], towerB = [], towerC = []; var toMove = null; var idF=" ", idT= " "; var nMovements = 0, nTotalMovements = 0, nWrongMoves = 0, nDisks = 2; var moves = [], totalMoves = []; //vector to save movements var acertou=0; var start; var optimalSolution; //NavyBlue Lime Fuchsia yellow Orange LightSteelBlue red var colors = ["#000080","#00FF00", "#FF00FF", "yellow", "#FFA500", "#B0C4DE","red"]; var pat = [], sources = ['imgs/baseText.png', 'imgs/disk1.png', 'imgs/disk2.png', 'imgs/disk3.png', 'imgs/disk4.png', 'imgs/disk5.png', 'imgs/disk6.png']; loadIMGS(nDisks); function loadImage(url) { return new Promise((resolve, reject) => { let img = new Image(); img.addEventListener('load', e => resolve(img)); img.addEventListener('error', () => { reject(new Error(`Failed to load image's URL: ${url}`)); }); img.src = url; }); } function loadIMGS(n){ var allImgs = sources.map(function(path){ return loadImage(path) }); Promise.all(allImgs).then(function(imgs){ for (var i = imgs.length - 1; i >= 0; i--) { pat[i] = context.createPattern(imgs[i], "repeat"); } }).then(function(){ inicio(n); }); }