텍스트 파일을 만들면 픽셀로 렌더링된다는 생각이 들었습니다. 첫 번째 테스트가 성공합니다. 나는 그것에 대해 하나의 픽셀을 가졌다. 이제 더 많은 픽셀을 넣으면 작동하지 않습니다. 여기 코드는 다음과 같습니다while JavaScript의 charAt
여기xhr=new XMLHttpRequest();
xhr.open("GET", "graphtest.prg", false);
xhr.send();
document.write(xhr.responseText);
var file=xhr.responseText;
var c=0;
var bad=false;
var val=0;
var rgbs="rgb(";
while(c<file.length && bad==false) {
//alert(file.charAt(c));
cc=file.charAt(c);
if (cc=="P" || cc=="R" || cc=="G") {
// magic
}
else {
if (cc=="{") {
if (val!=5) {
var newelem=document.createElement("span");
newelem.innerHTML=" ";
/*newelem.style.width="1px";
newelem.style.height="1px";
newelem.position="absolute";*/
newelem.className="graf";
}
}
else if (cc=="'") {
c++;
cc=file.charAt(c);
switch (val) {
case 0:
//alert("RUN");
var num=""+cc.toString();
c++;
while(!isNaN(file.charAt(c))) {
num+=file.charAt(c).toString();
c++;
}
newelem.style.left=num+"px";
//alert(num);
val++;
c++;
continue;
break;
case 1:
var num=""+cc.toString();
c++;
while(!isNaN(file.charAt(c))) {
num+=file.charAt(c).toString();
c++;
}
newelem.style.top=num+"px";
//alert(num);
val++;
c++;
continue;
break;
case 2:
var num=""+cc.toString();
c++;
while(!isNaN(file.charAt(c))) {
num+=file.charAt(c).toString();
c++;
}
rgbs+=num+",";
//alert(num);
val++;
c++;
continue;
break;
case 3:
var num=""+cc.toString();
c++;
while(!isNaN(file.charAt(c))) {
num+=file.charAt(c).toString();
c++;
}
rgbs+=num+",";
//alert(num);
val++;
c++;
continue;
break;
case 4:
var num=""+cc.toString();
c++;
while(!isNaN(file.charAt(c))) {
num+=file.charAt(c).toString();
c++;
}
rgbs+=num+")";
//alert(num);
val++;
c++;
continue;
break;
case 5:
newelem.style.backgroundColor=rgbs;
document.body.appendChild(newelem);
val=0;
rgbs="";
newelem=null;
cc="";
num="";
break;
}
}
if (val==5) {
newelem.style.backgroundColor=rgbs;
document.body.appendChild(newelem);
val=0;
rgbs="";
//newelem=null;
//c;
alert(file.charAt(c));
cc="";
num="";
}
}
c++;
}
는 "그래픽 텍스트"파일입니다
PRG{'100','200','0','255','0'}{'200','100','0','0','255'}
첫 번째 픽셀이 성공적으로 렌더링되지만, 제 2 픽셀은 배경색이 없습니다. 파싱 문제인가요?
음, 파서가 다소 혼란 스럽습니다. 0, 1, 2, 3, 4의 경우 똑같은 일을하지 않습니까? – Bergi
그래픽 표시를 위해 절대 위치 스팬 대신 '
'number'표현에 문자열 대신 숫자를 사용해야하므로 일부 메모리를 절약하십시오. – Ridcully