📝 add compilation time & update test/ppmgen.nas

This commit is contained in:
ValKmjolnir 2022-08-21 00:26:16 +08:00
parent 978957aca7
commit da8aa4744e
2 changed files with 35 additions and 22 deletions

View File

@ -52,7 +52,7 @@ void logo()
<<" / \\/ / _` / __|/ _` | |\n"
<<" / /\\ / (_| \\__ \\ (_| | |\n"
<<" \\_\\ \\/ \\__,_|___/\\__,_|_|\n"
<<"nasal ver : "<<__nasver<<" ("<<__DATE__<<")\n"
<<"nasal ver : "<<__nasver<<" ("<<__DATE__<<" "<<__TIME__<<")\n"
<<"c++ std : "<<__cplusplus<<"\n"
<<"thanks to : https://github.com/andyross/nasal\n"
<<"code repo : https://github.com/ValKmjolnir/Nasal-Interpreter\n"

View File

@ -1,24 +1,37 @@
var RD=func(i,j){
return bits.u32_and(255,j/255*255.999);
}
var GR=func(i,j){
return bits.u32_and(255,i/255*255.999);
}
var BL=func(i,j){
return bits.u32_and(255,0.25*255.999);
}
var pixel_write=func(fd,i,j){
var color=RD(i,j)~" "~GR(i,j)~" "~BL(i,j)~" ";
io.write(fd,color);
import.stl.process_bar;
var ppm=func(filename,width,height,RGB){
# P3 use ASCII number
# P6 use binary character
var fd=io.open(filename,"wb");
io.write(fd,"P3\n"~width~" "~height~"\n255\n");
for(var i=0;i<height;i+=1){
for(var j=0;j<width;j+=1)
io.write(fd,RGB(i,j));
io.write(fd,"\n");
}
io.close(fd);
}
var fd=io.open("a.ppm","wb");
# P3 use ASCII number
# P6 use binary character
io.write(fd,"P3\n256 256\n255\n");
for(var i=255;i>=0;i-=1){
for(var j=0;j<256;j+=1)
pixel_write(fd,i,j);
io.write(fd,"\n");
var width=1280;
var height=720;
var bar=process_bar.bar(front:os.platform()=="windows"?"sharp":"block",back:"point",sep:"line",length:50);
var f=func(i,j){
var (yMin,yMax,xMin,xMax)=(-0.9,0.9,-2.2,1);
var (yDel,xDel)=(yMax-yMin,xMax-xMin);
var (y,x)=((i/height)*yDel+yMin,(j/width)*xDel+xMin);
var (x0,y0)=(x,y);
for(var iter=0;iter<25;iter+=1){
var (x1,y1)=((x0*x0)-(y0*y0)+x,2*x0*y0+y);
(x0,y0)=(x1,y1);
if((x0*x0)+(y0*y0)>4){
break;
}
}
var progress=(i*width+j+1)/(width*height);
print(bar.bar(progress)," ",progress*100,"% \r");
iter=int(iter/25*255);
return iter~" "~iter~" "~iter~" ";
}
io.close(fd);
ppm("a.ppm",width,height,f);
println("\nfinished.");