Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- var canvas = document.getElementById("grafo");
- var ctx = canvas.getContext("2d");
- ctx.beginPath();
- ctx.moveTo(250,0);
- ctx.lineTo(250,500);
- ctx.moveTo(0,250);
- ctx.lineTo(500,250);
- ctx.fill();
- ctx.stroke();
- ctx.closePath();
- function controlloValori()
- {
- var i=0;
- var a=document.getElementById("a").value;
- var b=document.getElementById("b").value;
- var c=document.getElementById("c").value;
- if(a==0)
- { alert('Metti un valore maggiore di 0 se vuoi disegnare una parabola, scemo!');
- return false;
- }
- else
- document.getElementById("errore").innerHTML="";
- for(i=0;i<a.length;i++)
- {
- if((a.charAt(i)>='a') && (a.charAt(i)<='z'))
- {
- alert('Inserisci solo numeri, idiota!');
- return false;
- }
- else
- document.getElementById("errore").innerHTML="";
- }
- for(i=0;i<b.length;i++)
- {
- if((b.charAt(i)>='a') && (b.charAt(i)<='z'))
- {
- alert('Devi mettere solo numeri, idiota');
- return false;
- }
- else
- document.getElementById("errore").innerHTML="";
- }
- for(i=0;i<c.length;i++)
- {
- if((c.charAt(i)>='a') && (c.charAt(i)<='z'))
- {
- alert('Inserisci solo numeri, non lettere!');
- return false;
- }
- else
- document.getElementById("errore").innerHTML="";
- }
- return true;
- }
- function disegnaParabola()
- {
- if(controlloValori()==false)
- return;
- var a=document.getElementById("a").value;
- var b=document.getElementById("b").value;
- var c=document.getElementById("c").value;
- ctx.beginPath();
- var x;
- var y;
- var x1;
- var y1;
- ctx.beginPath();
- for(var i=-30.0;i<30.0;i=i+0.1)
- {
- x=calcolax(i);
- y=calcolay(calcolaf(i,a,b,c));
- x1=calcolax(i+0.1);
- y1=calcolay(calcolaf(i+0.1,a,b,c));
- ctx.moveTo(x1,y1);
- ctx.lineTo(x,y);
- ctx.fill();
- ctx.stroke();
- }
- ctx.closePath();
- }
- function calcolaf(x,a,b,c)
- {
- return (1.0*a*x*x+b*x+c);
- }
- function calcolay(y)
- {
- return (250+10*(-y));
- }
- function calcolax(x)
- {
- return (250+10*x);
- }
- function pulisciCanvas()
- {
- location.reload();
- document.getElementById("a").value="";
- document.getElementById("b").value="";
- document.getElementById("c").value="";
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement