)
// Moncalieri (TO)
//
// La copia e' libera ed incoraggiata a patto che questo
// file HTML non venga modificato in nessuna parte.
//------------------------------------------------------
var notazione='H'; // puo' essere D (= decimale) oppure H (= esadecimale)
var modo='B'; // cambia colore testo (T) o sfondo (B)
var num_col = 140; // numero dei colori predefiniti
var num_col_tot = 150; // numero dei colori totali (predefiniti+utente)
/*--- DATABASE COLORI ---*/
var datacol = new init_array(150); // codici dei colori
var nomecol = new init_array(150); // nomi dei colori
var usercol = new init_array(10); // nomi colori utente
var txtcol,backcol; // colori testo-sfondo correnti
// messaggi di testo (italiano)
var msg1 = "colore utente";
var msg2 = " non e' stato ancora impostato!";
var msg3 = "Il colore selezionato non e' corretto !";
var msg4 = " e' un colore predefinito e non puo' essere modificato!";
var msg5 = "Inserisci un nome per il nuovo colore (opzionale):";
var msg6 = "Il nome del colore digitato esiste gia'!";
var msg7 = " verra' impostato con ";
var msg8 = "Sono stati impostati i seguenti nuovi colori :";
var msg9 = "Salvo le modifiche ?";
var msg10 = "Le modifiche ai colori non sono state salvate.";
var msg11 = "Sono disponibili i seguenti colori definiti dall'utente:";
var msg12 = "e' stato realizzato da";
var msg13 = "La distribuzione di questo applet e' libera ed incoraggiata";
// Text message (English)
// Note for a english user:
// Remove this comments (/* and */) from the variables msgXX below and add
// them between the variable msgXX above (with italian text).
// This is the ONLY modify allowed in the code of this script
/* var msg1 = "user color";
var msg2 = " is not set yet !";
var msg3 = "The color is not correct !";
var msg4 = " cannot be modificated!";
var msg5 = "Insert a name for the new color (opzional):";
var msg6 = "The color name already exist !";
var msg7 = " will be set with ";
var msg8 = "The following user colors are set:";
var msg9 = "Save colors ?";
var msg10 = "The new colors are not been saved.";
var msg11 = "The following user colors are avaiable :";
var msg12 = "is made by";
var msg13 = "The copy of this applet is free and encourage"; */
// Inizializza un array
function init_array()
{
this.length = init_array.arguments.length;
for (var i=0;i3)||(str.length==0)) return 0;
for(i=0;i'9')) return 0;
n = eval(str);
if ((n<0)||(n>255)) return 0;
return 1;
}
// Ritorna 1 se str e' un numero esadecimale (00-FF)
function is_hex(str)
{
var i;
if ((str.length>2)||(str.length==0)) return 0;
for(i=0;i='0')&&(str.charAt(i)<='9'))||
(str.charAt(i)=='a')||(str.charAt(i)=='A')||
(str.charAt(i)=='b')||(str.charAt(i)=='B')||
(str.charAt(i)=='c')||(str.charAt(i)=='C')||
(str.charAt(i)=='d')||(str.charAt(i)=='D')||
(str.charAt(i)=='e')||(str.charAt(i)=='E')||
(str.charAt(i)=='f')||(str.charAt(i)=='F') ))
return 0;
return 1;
}
function init_listacol()
{
var i;
for (i=0;idec
function valore_dec(c)
{
var n=0;
if (c<='9') n=eval(c);
if ((c=='A')||(c=='a')) n=10;
if ((c=='B')||(c=='b')) n=11;
if ((c=='C')||(c=='c')) n=12;
if ((c=='D')||(c=='d')) n=13;
if ((c=='E')||(c=='e')) n=14;
if ((c=='F')||(c=='f')) n=15;
return n;
}
// converte una cifra dec->hex
function valore_hex(n)
{
if (n<=9) return n;
if (n==10) return 'A';
if (n==11) return 'B';
if (n==12) return 'C';
if (n==13) return 'D';
if (n==14) return 'E';
if (n==15) return 'F';
}
// CONVERSIONE Esadecimale -> Decimale
// -----------------------------------
function hex_to_dec(hex)
{
var d=0,H=0,L=0;
H=valore_dec(hex.charAt(0));
L=valore_dec(hex.charAt(1));
d=H*16+L;
return d;
}
// CONVERSIONE Decimale -> Esadecimale
// -----------------------------------
function dec_to_hex(str_dec)
{
var H=0,L=0;
var S="";
var dec=0;
dec = eval(str_dec);
H=Math.floor(dec/16);
L=dec%16;
S+=valore_hex(H);
S+=valore_hex(L);
return S;
}
// dai 3 numeri sui display
// restituisce una stringa del tipo RRGGBB
// oppure err se c'e' un errore
function stringa_color()
{
var R,G,B;
var n;
R = document.form1.red.value;
G = document.form1.green.value;
B = document.form1.blue.value;
if (notazione=='H')
{
/* controlli */
if (is_hex(R)!=1) return "err";
if (is_hex(G)!=1) return "err";
if (is_hex(B)!=1) return "err";
}
if (notazione=='D')
{
/* controlli */
if (is_byte(R)!=1) return "err";
if (is_byte(G)!=1) return "err";
if (is_byte(B)!=1) return "err";
R=dec_to_hex(R);
G=dec_to_hex(G);
B=dec_to_hex(B);
}
return (R+G+B);
}
// VISUALIZZA un nuovo colore
// --------------------------
function view_color()
{
var str;
str = stringa_color();
if (str!="err")
{
if (document.form1.elemento[0].checked==true) document.bgColor=str;
if (document.form1.elemento[1].checked==true) document.fgColor=str;
}
else
window.alert(msg3); // msg3 = Il colore selezionato non e' corretto !
}
// Cambia Notazione (Dec,Hex)
// --------------------------
function cambia_not()
{
var tipo="";
if (document.form1.notazione[0].checked==true) tipo='H';
if (document.form1.notazione[1].checked==true) tipo='D';
if ((notazione=='H')&&(tipo=='D'))
{
document.form1.red.value = hex_to_dec(document.form1.red.value);
document.form1.green.value = hex_to_dec(document.form1.green.value);
document.form1.blue.value = hex_to_dec(document.form1.blue.value);
}
if ((notazione=='D')&&(tipo=='H'))
{
document.form1.red.value = dec_to_hex(document.form1.red.value);
document.form1.green.value = dec_to_hex(document.form1.green.value);
document.form1.blue.value = dec_to_hex(document.form1.blue.value);
}
notazione=tipo;
}
// Modifica colore Testo<->Sfondo
// ------------------------------
function switch_col()
{
if ((modo=='B')&&(document.form1.elemento[1].checked==true))
{
modo='T';
backcol=stringa_color();
display(textcol);
document.fgColor=textcol;
}
if ((modo=='T')&&(document.form1.elemento[0].checked==true))
{
modo='B';
textcol=stringa_color();
display(backcol);
document.BgColor=backcol;
}
}
//--------------------------
// MEMORIZZA un nuovo colore
//--------------------------
function memo_new_col()
{
var nome,newname="";
var esci,i,j;
for (i=0; i0)
{
var str=msg11 +"\n";
// msg11 = Sono disponibili i seguenti colori definiti dall'utente:
for(l=num_col;l0)) document.form1.red.value--;
}
if (document.form1.VariaG.checked==true)
{
if ((segno=='+')&&(document.form1.green.value<255)) document.form1.green.value++;
if ((segno=='-')&&(document.form1.green.value>0)) document.form1.green.value--;
}
if (document.form1.VariaB.checked==true)
{
if ((segno=='+')&&(document.form1.blue.value<255)) document.form1.blue.value++;
if ((segno=='-')&&(document.form1.blue.value>0)) document.form1.blue.value--;
}
/* riconversione in decimale */
if (notazione=='H')
{
document.form1.red.value = dec_to_hex(document.form1.red.value);
document.form1.green.value = dec_to_hex(document.form1.green.value);
document.form1.blue.value = dec_to_hex(document.form1.blue.value);
}
view_color();
}
//------------------
// Pulsante di ABOUT
//------------------
function info()
{
var str;
str="ColorCalc vers.1.0\n";
str+="-------------------------------\n";
str+=msg12; // msg12 = e' stato realizzato da
str+="\nLuca Galli\n";
str+=msg13; // msg13 = La distribuzione di questo applet e' libera ed incoraggiata
window.alert(str);
}
//-->
ColorCalc
ColorCalc (calcolatrice per il colore)
Permette di creare un colore a partire dalle sue coordinate cromatiche (RGB). Il colore viene visualizzato come colore di background oppure come colore di testo.
Le principali caratteristiche sono:
- Inserimento diretto delle 3 coordinate cromatiche, in notazione decimale o esadecimale (a scelta) e con controllo del range di variazione.
- Possibilità di modificare il colore di background oppure il colore di testo (a scelta). Questo permette di studiare l'accostamento cromatico tra colore sfondo e colore testo.
- Aumentare o diminuire contemporaneamente uno, due o tutti e tre le coordinate cromatiche (mediante i pulsanti + e -) permettendo correzioni "fini".
- Scegliere un colore in una lista di 140 colori predefiniti
- Memorizzare fino ad un massimo di 10 colori (a scelta) creati dall'utente. I nuovi colori memorizzati non vengono persi quando si esce dall'applet in quanto vengono memorizzati sotto forma di Cookie.
- Fornisce un'esauriente guida, richiamabile mediante la pressione del pulsante HELP.
Download ColorCal in formato ZIP (11KB), è gratis!