Marche aléatoire
r = 20
Xmin = -r
Xmax = r
Ymin = -r
Ymax = r
traceG()
M = [0,0]
N = [0,0]
pasx = 0
pasy = 0
n = 0
k = 1
function deplacement(){
n = n+1
N[0] = M[0]
N[1] = M[1]
na = Math.random()
if (na < 0.25){ pasx = -1; pasy = 0 }
if (0.25 <= na && na < 0.5){ pasx = 1; pasy = 0 }
if (0.5 <= na && na < 0.75){ pasx = 0; pasy = -1 }
if (0.75 <= na && na <= 1){ pasx = 0; pasy = 1 }
M[0] = M[0]+pasx
M[1] = M[1]+pasy
if(M[0]==0 && M[1]==0){k = k+1}
document.getElementById("infos").innerHTML = "Passage(s) par l'origine : "+k+"
Nombre de déplacements : "+n;
segment(N,M)
}
setInterval(function (){deplacement()},50)