// ------------------ SVG et canvas ------------------ // Cette fonction calcule tous les points de la fonction mathématique. // Elle place chaque coordonnée "x" et "y" dans les tableaux "pointX" et "pointY" // A la fin, elle choisi la méthode d'affichage entre : // 1) une seule image SVG // 2) plusieurs images SVG function evaluerSVG(eq) { borneXGauche = parseFloat(document.getElementById("borneXGauche").value) borneXDroite = parseFloat(document.getElementById("borneXDroite").value) borneYGauche = parseFloat(document.getElementById("borneYGauche").value) borneYDroite = parseFloat(document.getElementById("borneYDroite").value) multiplicateurX = largeur/Math.abs(borneXDroite - borneXGauche) multiplicateurY = hauteur/Math.abs(borneYDroite - borneYGauche) lineWidth = document.getElementById("inputTaille").value var i = 0 var y1, p1 for(x=borneXGauche; x<=(borneXDroite+5*precision); x=x+precision){ y = eval(eq) if(!isNaN(y)){ i++ pointX[i] = (x - borneXGauche) * multiplicateurX pointY[i] = hauteur - ((y - borneYGauche) * multiplicateurY) pente[i] = hauteur - (((y-y1)/precision - borneYGauche)* multiplicateurY) pente2[i] = hauteur - ((((y-y1)/precision-p1)/precision - borneYGauche)* multiplicateurY) p1 = (y-y1)/precision y1 = y } } pente[1]=pente[2] pente2[2]=pente2[3] pente2[1]=pente2[2] //alert(pointX+'\n'+pointY) if(document.getElementById("selectMethodeAffichage").value == "svg2"){ calculerGraphSVG2(i) } else{ calculerGraphSVG(i) } } // Même fonction mais pour dessiner à l'aide de canvas function evaluerCanvas(eq) { borneXGauche = parseFloat(document.getElementById("borneXGauche").value) borneXDroite = parseFloat(document.getElementById("borneXDroite").value) borneYGauche = parseFloat(document.getElementById("borneYGauche").value) borneYDroite = parseFloat(document.getElementById("borneYDroite").value) multiplicateurX = largeur/Math.abs(borneXDroite - borneXGauche) multiplicateurY = hauteur/Math.abs(borneYDroite - borneYGauche) lineWidth = document.getElementById("inputTaille").value var i = 0 var y1, p1 for(x=borneXGauche; x<=(borneXDroite+5*precision); x=x+precision){ y = eval(eq) i++ if(!isNaN(y)){ pointX[i] = (x - borneXGauche) * multiplicateurX pointY[i] = hauteur - ((y - borneYGauche) * multiplicateurY) pente[i] = hauteur - (((y-y1)/precision - borneYGauche)* multiplicateurY) pente2[i] = hauteur - ((((y-y1)/precision-p1)/precision - borneYGauche)* multiplicateurY) p1 = (y-y1)/precision y1 = y } else{ pointX[i] = "undefined" pointY[i] = "undefined" pente[i] = "undefined" pente2[i] = "undefined" } } pente[1]=pente[2] pente2[2]=pente2[3] pente2[1]=pente2[2] calculerGraphCanevas(i) } // ---- SVG (une image) ---- // Génère le code HTML qui permet d'afficher le graphique et le place dans la div "affichage" function calculerGraphSVG2(fin){ image = "" for (i=1; i' } graphique = '' graphique = graphique + '' image = ''+image+graphique+' ' document.getElementById("affichage").innerHTML = image //alert(image) } // ---- SVG (images multiples) ---- // Créé les différents éléments pour dessiner la fonction mathématique // et les place dans la div "affichage" function calculerGraphSVG(fin){ document.getElementById("affichage").innerHTML = "" svg = document.createElementNS("http://www.w3.org/2000/svg", "svg") svg.setAttribute("width", "100%") svg.setAttribute("height", "100%") for (i=1; ihauteur)){ i++ } if ((pointY[i]>hauteur) && (pointY[i+1]<0)){ i++ } var ligne = document.createElementNS("http://www.w3.org/2000/svg", "line") ligne.setAttribute("x1", pointX[i]+decalageX) ligne.setAttribute("x2", pointX[i+1]+decalageX) ligne.setAttribute("y1", pointY[i]+decalageY) ligne.setAttribute("y2", pointY[i+1]+decalageY) ligne.setAttribute("stroke", couleurFonction) ligne.setAttribute("stroke-width", lineWidth) svg.appendChild(ligne) } // dérivée if(document.getElementById("checkDerivee").checked){ for (i=1; i' ctx = document.getElementById('canvas').getContext('2d') var undefined = true // Autres fonctions for(var i=0; i