From 078f2b6b6b6c950ee168e2c7c068820eb08d07c6 Mon Sep 17 00:00:00 2001 From: adplantade Date: Tue, 9 Jun 2020 16:13:32 +0200 Subject: [PATCH] Fonction empiler ne garde que les points visibles --- code/index.html | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/code/index.html b/code/index.html index 0ad5c1e..338c457 100644 --- a/code/index.html +++ b/code/index.html @@ -37,6 +37,7 @@ tab4=[]; tabTotal=[]; mousePos=[]; + colors=["red","blue","green","brown"]; width=300; // 6 lignes de 50px height=300; // 6 colonnes de 50px @@ -116,17 +117,41 @@ function empiler() { tabTotal=[]; - tab4.forEach(element => { - tabTotal.push(element); - }) - tab3.forEach(element => { + const unique = (val) => val.toString() != test.toString(); + exists=false; + + tab1.forEach(element => { tabTotal.push(element); }) tab2.forEach(element => { - tabTotal.push(element); + colors.forEach(col => { + test=[element[0],element[1],col]; + if(!exists) + exists=!tabTotal.every(unique); + }) + if(!exists) + tabTotal.push(element); + exists=false; }) - tab1.forEach(element => { - tabTotal.push(element); + tab3.forEach(element => { + colors.forEach(col => { + test=[element[0],element[1],col]; + if(!exists) + exists=!tabTotal.every(unique); + }) + if(!exists) + tabTotal.push(element); + exists=false; + }) + tab4.forEach(element => { + colors.forEach(col => { + test=[element[0],element[1],col]; + if(!exists) + exists=!tabTotal.every(unique); + }) + if(!exists) + tabTotal.push(element); + exists=false; }) toutDessiner(tabTotal,canvasT,ctxT);