Findet zwar wohl noch seltener Anwendung als meine Permutations-Funktion, aber was macht man nicht alles, wen einem langweilig ist..
Ursprünglich wollte ich kleine Animationen darin ablaufen lassen, aber das würde wohl jeden Browser in die Knie zwingen.. *g
Jetzt hab ich ihm ein paar Buchstaben beigebracht, die man in die Punktmatrix schreiben kann. Viel Spaß
function matrix(width,height){
// konstruktor
this.width=width;
this.height=height;
// ID erzeugen
this.id=1;
// nach anderen matrizen suchen
tbls=document.getElementsByTagName('table';
for(var i=0;i<tbls.length;i++){if(tbls[i].getAttribute('class'=='matrix'this.id++}
// zuruecksetzen
this.reset=function(){
this.field=new Array(this.height);
for(var y=0;y<height;y++){
this.field[y]=new Array(this.width);
for(var x=0;x<width;x++){this.field[y][x]=0}
}
}
this.reset();
// charmap mit je 7x11 feldern
this.charmap={
'A':[[0,0,1,1,0,0,0],[0,0,1,1,0,0,0],[0,1,0,0,1,0,0],[0,1,0,0,1,0,0],[0,1,1,1,1,0,0],[1,0,0,0,0,1,0],[1,0,0,0,0,1,0],[1,0,0,0,0,1,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]],
'B':[[1,1,1,1,1,0,0],[1,0,0,0,0,1,0],[1,0,0,0,0,1,0],[1,1,1,1,1,0,0],[1,0,0,0,0,1,0],[1,0,0,0,0,1,0],[1,0,0,0,0,1,0],[1,1,1,1,1,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]],
'C':[[0,0,1,1,1,0,0],[0,1,0,0,0,1,0],[1,0,0,0,0,0,0],[1,0,0,0,0,0,0],[1,0,0,0,0,0,0],[1,0,0,0,0,0,0],[0,1,0,0,0,1,0],[0,0,1,1,1,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]],
'D':[[1,1,1,1,0,0,0],[1,0,0,0,1,0,0],[1,0,0,0,0,1,0],[1,0,0,0,0,1,0],[1,0,0,0,0,1,0],[1,0,0,0,0,1,0],[1,0,0,0,1,0,0],[1,1,1,1,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]],
'E':[[1,1,1,1,1,1,0],[1,0,0,0,0,0,0],[1,0,0,0,0,0,0],[1,1,1,1,1,0,0],[1,0,0,0,0,0,0],[1,0,0,0,0,0,0],[1,0,0,0,0,0,0],[1,1,1,1,1,1,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]],
'F':[[1,1,1,1,1,1,0],[1,0,0,0,0,0,0],[1,0,0,0,0,0,0],[1,1,1,1,1,0,0],[1,0,0,0,0,0,0],[1,0,0,0,0,0,0],[1,0,0,0,0,0,0],[1,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]],
'G':[[0,0,1,1,1,0,0],[0,1,0,0,0,1,0],[1,0,0,0,0,0,0],[1,0,0,0,0,0,0],[1,0,0,0,1,1,0],[1,0,0,0,0,1,0],[0,1,0,0,0,1,0],[0,0,1,1,1,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]]
}
// rendern
this.render=function(){
if(document.getElementById(this.id)){this.update()}else{this.rendernew()}
}
// neu erstellen
this.rendernew=function(){
b='<table class="matrix" id="'+this.id+'">';
for(var y=0;y<height;y++){b+='<tr>';for(var x=0;x<width;x++){b+='<td class="'+((this.field[y][x]==0)?'n':'y'+'"></td>'}b+='</tr>';}
b+='</table>';
document.write(b);
}
// aktualisieren
this.update=function(){
var m=document.getElementById(this.id);
var tr=m.childNodes[0].childNodes;
for(var y=0;y<tr.length;y++){
var td=tr[y].childNodes;
for(var x=0;x<td.length;x++){
var v=this.field[y][x];
var c=td[x].getAttribute('class';
if((v==0&&c=='y'||(v==1&&c=='n'){td[x].setAttribute('class', (c=='y'?'n':'y'}
}
}
}
// zeichen schreiben
this.drawChr=function(y,x,chr){
for(y_c=0;y_c<11;y_c++){
for(x_c=0;x_c<7;x_c++){
this.field[y_c+y][x_c+x]=this.charmap[chr][y_c][x_c];
}
}
}
// feld aendern
this.toggle=function(y,x){
this.field[y][x]=(this.field[y][x]==0)?1:0;
}
}