Comment afficher un point de coordonnées variables avec JavaScript ?

Seror shared this question 6 years ago
Answered

Bonjour,

Dans un script JavaScript, je calcule les coordonnées réelles d'un point B(x,y) variable dans le plan à partir d'une double boucle "for".

Ma question est la suivante : comment faire, dans JavaScript, pour afficher chaque nouveau point calculé.

Dans mon script (voir le fichier joint), il se trouve que c'est toujours le dernier et le seul point qui s'affiche en fin de script.

Merci de votre aide.

Comments (3)

photo
1

Merci Noel pour ta réponse mais j'ai modifié mon script, en déplaçant les commandes d'affichage, mais cela ne fonctionne pas mieux.

Est-ce-que la commande n'est pas la bonne, je cale un peu (je débute en Java).

Sinon, j'ai une autre question, est-ce-que JavaScript sait traiter des variables complexes (produit, partie réelle et imaginaire) ... ?

photo
1

OK="Ok , oui !"; zr=0.2 ; zi=0.2; tmp=0.5; x=0.4 ; y=0.4;

var max=ggbApplet.getValue('max');

ggbApplet.evalCommand("B=(0.1,0.1)");

ggbApplet.evalCommand("SetTrace[ B , true ] ");

var n=1;

for (i=1; i<max; i++)

x= -1.5+0.01*i ;

{for (j=1; j<max; j++)

{ y= -1+0.01*j ; zr=x^2-y^2 + x ; zi=2*x*y + y ; k=0;

while ((zr^2+zi^2)<4 && (k<17))

{ tmp=zr; zr=zr^2-zi^2 + x ; zi=2*tmp*zi + y ; k=k+1 ;

ggbApplet.evalCommand("B"+n+"=("+zr+","+zi+")");

//ggbApplet.evalCommand("SetCoords[B , "+zr+","+zi+"] ");

ggbApplet.evalCommand("SetColor[B"+n +","+255/j+",0,"+255/i*max+"]");

ggbApplet.evalCommand("ShowLabel(B"+n+",false)");

n++;

// alert("OK=" +OK)

}}}

photo
1

var OK="Ok , oui !";

var zr=0.2 ; zi=0.2; tmp=0.5; x=0.4 ; y=0.4;

var max=ggbApplet.getValue('max');

ggbApplet.evalCommand("B=(0.1,0.1)");

ggbApplet.evalCommand("SetTrace[ B , true ] ");

var n=1;

var ListP="ListP={"

for (i=1; i<max; i++)

x= -1.5+0.01*i ;

{for (j=1; j<max; j++)

{ y= -1+0.01*j ; zr=x^2-y^2 + x ; zi=2*x*y + y ; k=0;

while ((zr^2+zi^2)<4 && (k<17))

{ tmp=zr; zr=zr^2-zi^2 + x ; zi=2*tmp*zi + y ; k=k+1 ;

if(n==1){

ListP=ListP+"("+zr+","+zi+")";

}else{

ListP=ListP+",("+zr+","+zi+")";

}

n++;

// alert("OK=" +OK)

}}}

ListP=ListP+"}";

ggbApplet.evalCommand(ListP);

photo
© 2023 International GeoGebra Institute