//
// FUNZIONI:
// setColor(c);
// setPoint(x,y);drawLine(x0,y0,x1,y1);
// drawRect(x0,y0,l,h);fillRect(x0,y0,l,h){
// drawOval(x,y,l,h);fillOval(x,y,l,h)
// drawArc(x,y,l,h,alpha0,alpha1);fillArc(x,y,l,h,alpha0,alpha1)
// drawString(s,x,y);puntone(x,y)
// drawimage(x,y,nomeFile)
// drawRombo(x0,y0,a,b);
// dueQuadrati(x,y,la,lb)
// inputVettore2D()
// assiEgrid20per20(xc,yc)
// debug() ;listato(funzione); i1n(n,istr)
//
// tabulaFunzione(f,x0,x1,deltaX)
// tabella2x2(a1,a2,a3,a4)
// w(x);wln(x);nprompt
//
//
// tabella();nuovaRiga();nuovoDato(x);fineTabella()
// quadrato(x);cubo(x);quartaPotenza(x);
// radice(x)
// dimezza(x);doppio(x);triplo(x);quadruplo(x)
// somma(a,b)
// sin(x);cos(x);tan(x)
// sol(a,b,c)
function dueQuadrati(x,y,la,lb){
l=Math.max(la,lb);
t=Math.min(la,lb);
for (var i=x;i<=x+l;i=i+1) {punto(i,y)}
for (var i=y;i<=y+l;i=i+1) {punto(x+l,i)}
for (var i=x;i<=x+l;i=i+1) {punto(i,y+l)}
for (var i=y;i<=y+l;i=i+1) {punto(x,i)}
x1=x+(l-t)/2;
y1=y+(l-t)/2;
for (var i=x1;i<=x1+t;i=i+1) {punto(i,y1)}
for (var i=y1;i<=y1+t;i=i+1) {punto(x1+t,i)}
for (var i=x1;i<=x1+t;i=i+1) {punto(i,y1+t)}
for (var i=y1;i<=y1+t;i=i+1) {punto(x1,i)}
}
function drawimage(x,y,i) {
document.writeln('');
}
function inputVettore2D(){ // By Amateis per inserire un vettore (x,y)
c=new Array(2);
c[0]=prompt('Inserisci la x');
c[1]=prompt('Inserisci la y');
return c;
}
function nprompt(x){// By Amateis: input di un numero
d=prompt(x);
return Number(d);
}
function drawRombo(x0,y0,a,b){ // By Amateis Rombo diagonali a,b centro x0, y0
m=a/b;
for (var i=(x0-b/2);i<=x0;i=i+0.1){
y1=-m*(i-(x0-b/2))+y0;
punto(i,y1);
y2=m*(i-(x0-b/2))+y0;
punto(i,y2);
}
for (var i=x0;i<=(x0+b/2);i=i+0.1){
y3=m*(i-x0)+(y0-a/2);
punto(i,y3);
y4=-m*(i-x0)+(y0+a/2);
punto(i,y4);
}
}
function fillRect(x0,y0,l,h){
if(l<0){l=-l;x0=x0-l;}
if(h<0){h=-h;y0=y0-h;}
x0=Math.floor(x0);y0=Math.floor(y0);
l=Math.ceil(l);h=Math.ceil(h);
for(var x=x0;x<=x0+l;x++){
for(var y=y0;y<=y0+h;y++){
document.write('·');
}
}
}
function fillOval(x,y,l,h){
rx=l/2;ry=h/2;
xc=x+rx;yc=y+ry
for(var xx=x+l;xx>=-x;xx--){
alpha=Math.acos((xx-x)/l)
drawLine(xc+rx*Math.cos(alpha),yc-ry*Math.sin(alpha),xc+rx*Math.cos(-alpha),yc-ry*Math.sin(-alpha));
}
}
function fillArc(x,y,l,h,alpha0,alpha1){
rx=l/2;ry=h/2;
xc=x+rx;yc=y+ry
da=Math.PI/180
for(var alpha=alpha0;alpha<=alpha1;alpha+=da){
drawLine(xc,yc,xc+rx*Math.cos(alpha+da),yc-ry*Math.sin(alpha+da));
}
}
function drawArc(x,y,l,h,alpha0,alpha1){
rx=l/2;ry=h/2;
xc=x+rx;yc=y+ry
da=Math.PI/360
for(var alpha=alpha0;alpha<=alpha1;alpha+=da){
drawLine(xc+rx*Math.cos(alpha),yc-ry*Math.sin(alpha),xc+rx*Math.cos(alpha+da),yc-ry*Math.sin(alpha+da));
}
}
function drawOval(x,y,l,h){
rx=l/2;ry=h/2;
xc=x+rx;yc=y+ry
da=Math.PI/360
for(var alpha=0;alpha<=6.29;alpha+=da){
drawLine(xc+rx*Math.cos(alpha),yc- ry*Math.sin(alpha),xc+rx*Math.cos(alpha+da),yc- ry*Math.sin(alpha+da));
}
}
function punto(x,y){ // By Nicco: Fa un puntino in coordinate x,y (Obsoleta)
w(' · ' );
}
function setPoint(x,y){ // By Nicco:Fa un puntino in coordinate x,y (In futuro restera' solo questa)
w(' · ' );
}
function tabulaFunzione(f,x0,x1,deltaX) { //By Gamba
document.writeln('
');
document.writeln(''+'x'+' | '+f);
for(var x=x0;x<=x1;x+=deltaX){
document.writeln(' |
'+x+' | '+eval (f));
}
document.writeln(' |
')
}
function setColor(c){
document.write('');
}
function drawRect(x0,y0,l,h){
x0=Math.floor(x0);y0=Math.floor(y0);
l=Math.ceil(l);h=Math.ceil(h);
drawLine(x0,y0,x0+l,y0);
drawLine(x0,y0,x0,y0+h);
drawLine(x0+l,y0+h,x0+l,y0);
drawLine(x0+l,y0+h,x0,y0+h);
}
function drawLine(x0,y0,x1,y1){
dx=x1-x0;dy=y1-y0;
if(y1>=y0){versoy=1}else{versoy=-1}
if(x1>=x0){versox=1}else{versox=-1}
npx=Math.abs(dx);npy=Math.abs(dy);
var i=0;
if( dx*dx >= dy*dy){ // tg <= 45 gradi
deY=dy/npx;
with(document){
while(i++<=npx){
write(
'.');
x0+=versox;y0+=deY
}
}
}
else{ // tg > 45 gradi
deX=dx/npy;
with(document){
while(i++<=npy){
write(
'.');
y0+=versoy;x0+=deX;
}
}
}
}
function debug() {// By Nicco:Apre una finestra nella quale si possono lanciare istruzioni javascript (utile se si vogliono provare le nuove funzioni o se si vuol vedere lo stato delle variabili)
query=' ';
while (query !="exit"){
query=prompt('"exit" per uscire',"");
if(query!="exit")eval(query);
}
}
function drawString(s,x,y){
document.write(
''+s+'');
}
// ------------- Utilities Stampa -------------------
// By Polistina : Stampa x (per non scrivere ogni volta document.writeln(x) )
function w(x){document.writeln(x)}
function wln(x){w(x+'
')}// By Lopiano e Banfo:Stampa x e va a capo
// ------------- Gestione Tabelle ------------------
function tabella() { w('') } // By Contotti: Apre un ambiente tabella
function nuovaRiga(){ w('') } // By Cordiano
function nuovoDato(x){ w(''+x) } // By Cordiano
function fineTabella(){ w(' |
') } // By Contotti
//------------------ Matematiche ------------------
function quartaPotenza(x){return(x*x*x*x)}// By Mazza
function cubo(x){return(x*x*x)} // By Marotta
function quadrato(x){return(x*x)} // By Cantoro
function radice(x){return Math.sqrt(x);}// By Gaiardo
function dimezza(x){return(x/2)} // By Zuppa
function doppio(x){return (x*2)} // By Picco
function triplo(x){return (x*4)} // By Goy
function quadruplo(x){return (x*4)} // By Volpe(restituisce il quadruplo dell'argomento)
function decuplo(x){return (x*10)} // By Goy
function somma(a,b){
return Number(Number(a)+Number(b))} // By Napolitano
function sin(x){return Math.sin(x)} // By Cavalieri
function cos(x){return Math.cos(x)} // By Cavalieri
function tan(x){return Math.tan(x)} // By Cavalieri
function sol(a,b,c){// By Campa:
v = new Array([3])
d= b*b-4*a*c;
if(d < 0){v[0]=v[1]=v[2]=0}
if(d == 0){
v[0]=v[1]= (-b+radice(d)) / (2*a);
v[2]=1
}
if(d > 0){
v[0]=(-b+radice(d))/(2*a);
v[1]=(-b-radice(d))/(2*a);
v[2]=2;
}
return v;
}
function i1n(n,istr){ // By Nicco
for(var i=1;i<=n;i++){eval(istr)}
}
function listato(f){
w(''+f.toString()+'' );
}
function puntone(x,y){
w(' * ' );
}
function puntoColorato (x,y,c){
w(' . ' );
}
function tabella2x2(a1,a2,a3,a4){ // by Zuppa
tabella();
nuovaRiga();nuovoDato(a1);nuovoDato(a2);
nuovaRiga();nuovoDato(a3);nuovoDato(a4);
fineTabella();
}
function assiEgrid20per20(xc,yc){
for(var y=-10;y<=10;y+=1){ // linee orizzontali
for(var x=xc-100;x<=xc+100;x+=1){
puntoColorato(x,yc-y*10,"green");
}
}
for(var x=-10;x<=10;x+=1){//linee verticali
for(var y=yc-100;y<=yc+100;y+=1){
puntoColorato(xc+x*10,y,"green");
}
}
for(var x=xc-100;x<=xc+100;x+=1){ // asse X
puntoColorato(x,yc,"black");
}
for(var y=yc-100;y<=yc+100;y+=1){// asse Y
puntoColorato(xc,y,"black");
}
for(var x=-10;x<=10;x+=1){ // linette verticali sull'asse X
puntoColorato(xc+x*10,yc-2,"blue");
puntoColorato(xc+x*10,yc-1,"blue");
puntoColorato(xc+x*10,yc-0,"blue");
puntoColorato(xc+x*10,yc+1,"blue");
puntoColorato(xc+x*10,yc+2,"blue");
}
for(var y=-10;y<=10;y+=1){ // linette orizzontali sull'asse y
puntoColorato(xc-2,yc-y*10,"blue");
puntoColorato(xc-1,yc-y*10,"blue");
puntoColorato(xc,yc-y*10,"blue");
puntoColorato(xc+1,yc-y*10,"blue");
puntoColorato(xc+2,yc-y*10,"blue");
}
}
//COSTANTI:
var PIGRECO=Math.PI;
var PIGRECOMEZZI=(Math.PI)/2;
INFINITO =1/0;
//