Advertisement
CrazedProgrammer

Surface API (Minified)

May 21st, 2015
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.82 KB | None | 0 0
  1. version="1.6.2"local a,b,c,d,e=math.floor,math.cos,math.sin,table.concat,{[1]="0",[2]="1",[4]="2",[8]="3",[16]="4",[32]="5",[64]="6",[128]="7",[256]="8",[512]="9",[1024]="a",[2048]="b",[4096]="c",[8192]="d",[16384]="e",[32768]="f"}local function f(g,h,i,j,k,l)local m=k-i;local n=m>0 and 1 or-1;m=2*math.abs(m)local o=l-j;local p=o>0 and 1 or-1;o=2*math.abs(o)g[(j-1)*h+i]=true;if m>=o then local q=o-m/2;while i~=k do if q>=0 and q~=0 or n>0 then q=q-m;j=j+p end;q=q+o;i=i+n;g[(j-1)*h+i]=true end else local q=m-o/2;while j~=l do if q>=0 and q~=0 or p>0 then q=q-o;i=i+n end;q=q+m;j=j+p;g[(j-1)*h+i]=true end end end;local r={setBounds=function(s,i,j,k,l)if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;if k<1 or i>s.width or l<1 or j>s.height then return end;if i<1 then i=1 end;if k>s.width then k=s.width end;if j<1 then j=1 end;if l>s.height then l=s.height end;s.x1,s.y1,s.x2,s.y2=i,j,k,l end,getBounds=function(s)return s.x1,s.y1,s.x2,s.y2 end,copy=function(s)local u=create(s.width,s.height)u.x1,u.y1,u.x2,u.y2,u.blink,u.curX,u.curY,u.overwrite=s.x1,s.y1,s.x2,s.y2,s.blink,s.curX,s.curY,s.overwrite;for v=1,s.width*s.height*3 do u.buffer[v]=s.buffer[v]end;return u end,save=function(s,w,x)x=x or"srf"local y=fs.open(w,"w")if x=="nfp"then local z=nil;for A=1,s.height do if A>1 then y.write("\n")end;for v=1,s.width do z=s.buffer[((A-1)*s.width+v)*3-1]if z then y.write(e[z])else y.write(" ")end end end elseif x=="nft"then local B,C,char=nil;for A=1,s.height do if A>1 then y.write("\n")end;B,C=nil;for v=1,s.width do if B~=s.buffer[((A-1)*s.width+v)*3-1]then y.write(string.char(30))B=s.buffer[((A-1)*s.width+v)*3-1]if B then y.write(e[B])else y.write(" ")end end;if C~=s.buffer[((A-1)*s.width+v)*3]then y.write(string.char(31))C=s.buffer[((A-1)*s.width+v)*3]if C then y.write(e[C])else y.write(" ")end end;char=s.buffer[((A-1)*s.width+v)*3-2]if char then y.write(char)else y.write(" ")end end end elseif x=="srf"then y.write(s:saveString())end;y.close()end,saveString=function(s)local D={"_"..string.format("%04x",s.width)..string.format("%04x",s.height)}for A=1,s.height do for v=1,s.width do if s.buffer[((A-1)*s.width+v)*3-2]then D[#D+1]=string.format("%02x",s.buffer[((A-1)*s.width+v)*3-2]:byte(1))else D[#D+1]="__"end;if s.buffer[((A-1)*s.width+v)*3-1]then D[#D+1]=e[s.buffer[((A-1)*s.width+v)*3-1]]else D[#D+1]="_"end;if s.buffer[((A-1)*s.width+v)*3]then D[#D+1]=e[s.buffer[((A-1)*s.width+v)*3]]else D[#D+1]="_"end end end;return d(D)end,getTerm=function(s)local term,B,C={},colors.black,colors.white;function term.write(D)s:drawText(s.curX,s.curY,tostring(D),B,C)s.curX=s.curX+#tostring(D)end;function term.blit(D,E,F)for v=1,#D do if s.curX>=s.x1 and s.curY>=s.y1 and s.curX<=s.x2 and s.curY<=s.y2 then s.buffer[((s.curY-1)*s.width+s.curX)*3-2]=D:sub(v,v)s.buffer[((s.curY-1)*s.width+s.curX)*3-1]=2^tonumber(F:sub(v,v),16)s.buffer[((s.curY-1)*s.width+s.curX)*3]=2^tonumber(E:sub(v,v),16)end;s.curX=s.curX+1 end end;function term.clear()s:clear(" ",B,C)end;function term.clearLine(G)s:drawHLine(s.x1,s.x2,s.curY," ",B,C)end;function term.getCursorPos()return s.curX,s.curY end;function term.setCursorPos(H,I)s.curX,s.curY=a(H),a(I)end;function term.setCursorBlink(J)s.blink=J end;function term.isColor()return true end;term.isColour=term.isColor;function term.setTextColor(z)C=z end;term.setTextColour=term.setTextColor;function term.setBackgroundColor(z)B=z end;term.setBackgroundColour=term.setBackgroundColor;function term.getSize()return s.width,s.height end;function term.scroll(G)s:shift(0,-G)end;function term.getTextColor()return C end;term.getTextColour=term.getTextColor;function term.getBackgroundColor()return B end;term.getBackgroundColour=term.getBackgroundColor;return term end,render=function(s,K,H,I,L,M,N,O)K,H,I,L,M,N,O=K or term,H or 1,I or 1,L or 1,M or 1,N or s.width,O or s.height;if L>N then local t=L;L,N=N,t end;if M>O then local t=M;M,O=O,t end;if N<1 or L>s.width or O<1 or M>s.height then return end;if L<1 then L=1 end;if N>s.width then N=s.width end;if M<1 then M=1 end;if O>s.height then O=s.height end;local P={}if K.blit then local D,F,E={},{},{}for A=M,O do for v=L,N do D[v-L+1]=s.buffer[((A-1)*s.width+v)*3-2]or" "F[v-L+1]=e[s.buffer[((A-1)*s.width+v)*3-1]or 32768]E[v-L+1]=e[s.buffer[((A-1)*s.width+v)*3]or 1]end;P[#P+1]=I+A-M;P[#P+1]=d(D)P[#P+1]=d(E)P[#P+1]=d(F)end;for v=1,#P,4 do K.setCursorPos(H,P[v])K.blit(P[v+1],P[v+2],P[v+3])end else local D,B,C,Q,R="",0,0;for A=M,O do P[#P+1]=1;P[#P+1]=I+A-M;for v=L,N do Q,R=s.buffer[((A-1)*s.width+v)*3-1]or 32768,s.buffer[((A-1)*s.width+v)*3]or 1;if Q~=B then B=Q;if D~=""then P[#P+1]=4;P[#P+1]=D;D=""end;P[#P+1]=2;P[#P+1]=B end;if R~=C then C=R;if D~=""then P[#P+1]=4;P[#P+1]=D;D=""end;P[#P+1]=3;P[#P+1]=C end;D=D..s.buffer[((A-1)*s.width+v)*3-2]or" "end;P[#P+1]=4;P[#P+1]=D;D=""end;local S,T=nil;for v=1,#P,2 do S,T=P[v],P[v+1]if S==1 then K.setCursorPos(H,T)elseif S==2 then K.setBackgroundColor(T)elseif S==3 then K.setTextColor(T)else K.write(T)end end end;if s.blink and s.curX>=1 and s.curY>=1 and s.curX<=s.width and s.curY<=s.height then K.setCursorPos(H+s.curX-L,I+s.curY-M)K.setCursorBlink(true)elseif s.blink==false then K.setCursorBlink(false)s.blink=nil end;return#P/2 end,clear=function(s,char,B,C)local U=s.overwrite;s.overwrite=true;s:fillRect(s.x1,s.y1,s.x2,s.y2,char,B,C)s.overwrite=U end,drawPixel=function(s,H,I,char,B,C)if H<s.x1 or I<s.y1 or H>s.x2 or I>s.y2 then return end;if char or s.overwrite then s.buffer[((I-1)*s.width+H)*3-2]=char end;if B or s.overwrite then s.buffer[((I-1)*s.width+H)*3-1]=B end;if C or s.overwrite then s.buffer[((I-1)*s.width+H)*3]=C end end,getPixel=function(s,H,I)if H<1 or I<1 or H>s.width or I>s.height then return end;return s.buffer[((I-1)*s.width+H)*3-2],s.buffer[((I-1)*s.width+H)*3-1],s.buffer[((I-1)*s.width+H)*3]end,drawText=function(s,H,I,E,B,C)local V=H;for v=1,#E do if E:sub(v,v)~="\n"then if H>=s.x1 and I>=s.y1 and H<=s.x2 and I<=s.y2 then s.buffer[((I-1)*s.width+H)*3-2]=E:sub(v,v)if B or s.overwrite then s.buffer[((I-1)*s.width+H)*3-1]=B end;if C or s.overwrite then s.buffer[((I-1)*s.width+H)*3]=C end end else H=V-1;I=I+1 end;H=H+1 end end,drawLine=function(s,i,j,k,l,char,B,C)local m=k-i;local n=m>0 and 1 or-1;m=2*math.abs(m)local o=l-j;local p=o>0 and 1 or-1;o=2*math.abs(o)s:drawPixel(i,j,char,B,C)if m>=o then local q=o-m/2;while i~=k do if q>=0 and q~=0 or n>0 then q=q-m;j=j+p end;q=q+o;i=i+n;s:drawPixel(i,j,char,B,C)end else local q=m-o/2;while j~=l do if q>=0 and q~=0 or p>0 then q=q-o;i=i+n end;q=q+m;j=j+p;s:drawPixel(i,j,char,B,C)end end end,drawLines=function(s,W,X,char,B,C)X=X or 1;if X==1 then for v=1,#W,4 do s:drawLine(W[v],W[v+1],W[v+2],W[v+3],char,B,C)end elseif X==2 then local Y,Z=W[1],W[2]for v=3,#W,2 do local _,a0=W[v],W[v+1]s:drawLine(Y,Z,_,a0,char,B,C)Y=_;Z=a0 end elseif X==3 then local a1,a2=W[1],W[2]for v=3,#W,2 do s:drawLine(a1,a2,W[v],W[v+1],char,B,C)end end end,drawHLine=function(s,i,k,I,char,B,C)if i>k then local t=i;i,k=k,t end;if I<s.y1 or I>s.y2 or k<s.x1 or i>s.x2 then return end;if i<s.x1 then i=s.x1 end;if k>s.x2 then k=s.x2 end;if char or s.overwrite then for H=i,k do s.buffer[((I-1)*s.width+H)*3-2]=char end end;if B or s.overwrite then for H=i,k do s.buffer[((I-1)*s.width+H)*3-1]=B end end;if C or s.overwrite then for H=i,k do s.buffer[((I-1)*s.width+H)*3]=C end end end,drawVLine=function(s,j,l,H,char,B,C)if j>l then local t=j;j,l=l,t end;if H<s.x1 or H>s.x2 or l<s.y1 or j>s.y2 then return end;if j<s.y1 then j=s.y1 end;if l>s.y2 then l=s.y2 end;if char or s.overwrite then for I=j,l do s.buffer[((I-1)*s.width+H)*3-2]=char end end;if B or s.overwrite then for I=j,l do s.buffer[((I-1)*s.width+H)*3-1]=B end end;if C or s.overwrite then for I=j,l do s.buffer[((I-1)*s.width+H)*3]=C end end end,drawRect=function(s,i,j,k,l,char,B,C)s:drawHLine(i,k,j,char,B,C)s:drawHLine(i,k,l,char,B,C)s:drawVLine(j,l,i,char,B,C)s:drawVLine(j,l,k,char,B,C)end,drawRoundRect=function(s,i,j,k,l,char,B,C)s:drawHLine(i+1,k-1,j,char,B,C)s:drawHLine(i+1,k-1,l,char,B,C)s:drawVLine(j+1,l-1,i,char,B,C)s:drawVLine(j+1,l-1,k,char,B,C)end,drawRoundedRect=function(s,i,j,k,l,a3,char,B,C)s:drawHLine(i+a3,k-a3,j,char,B,C)s:drawHLine(i+a3,k-a3,l,char,B,C)s:drawVLine(j+a3,l-a3,i,char,B,C)s:drawVLine(j+a3,l-a3,k,char,B,C)s:drawArc(i,j,i+a3*2+2,j+a3*2+2,-math.pi,-math.pi/2,char,B,C)s:drawArc(k,j,k-a3*2-2,j+a3*2+2,0,-math.pi/2,char,B,C)s:drawArc(i,l,i+a3*2+2,l-a3*2-2,math.pi,math.pi/2,char,B,C)s:drawArc(k,l,k-a3*2-2,l-a3*2-2,0,math.pi/2,char,B,C)end,fillRect=function(s,i,j,k,l,char,B,C)if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;if k<s.x1 or i>s.x2 or l<s.y1 or j>s.y2 then return end;if i<s.x1 then i=s.x1 end;if k>s.x2 then k=s.x2 end;if j<s.y1 then j=s.y1 end;if l>s.y2 then l=s.y2 end;if char or s.overwrite then for I=j,l do for H=i,k do s.buffer[((I-1)*s.width+H)*3-2]=char end end end;if B or s.overwrite then for I=j,l do for H=i,k do s.buffer[((I-1)*s.width+H)*3-1]=B end end end;if C or s.overwrite then for I=j,l do for H=i,k do s.buffer[((I-1)*s.width+H)*3]=C end end end end,fillRoundRect=function(s,i,j,k,l,char,B,C)s:drawHLine(i+1,k-1,j,char,B,C)s:drawHLine(i+1,k-1,l,char,B,C)s:drawVLine(j+1,l-1,i,char,B,C)s:drawVLine(j+1,l-1,k,char,B,C)s:fillRect(i+1,j+1,k-1,l-1,char,B,C)end,fillRoundedRect=function(s,i,j,k,l,a3,char,B,C)s:fillRect(i+a3,j,k-a3,l,char,B,C)s:fillRect(i,j+a3,i+a3,l-a3,char,B,C)s:fillRect(k-a3,j+a3,k,l-a3,char,B,C)s:fillPie(i,j,i+a3*2+2,j+a3*2+2,-math.pi,-math.pi/2,char,B,C)s:fillPie(k,j,k-a3*2-2,j+a3*2+2,0,-math.pi/2,char,B,C)s:fillPie(i,l,i+a3*2+2,l-a3*2-2,math.pi,math.pi/2,char,B,C)s:fillPie(k,l,k-a3*2-2,l-a3*2-2,0,math.pi/2,char,B,C)end,drawTriangle=function(s,i,j,k,l,a4,a5,char,B,C)s:drawLine(i,j,k,l,char,B,C)s:drawLine(k,l,a4,a5,char,B,C)s:drawLine(a4,a5,i,j,char,B,C)end,fillTriangle=function(s,i,j,k,l,a4,a5,char,B,C)local a6,a7,a8,a9=i,j,i,j;if k<a6 then a6=k end;if a4<a6 then a6=a4 end;if l<a7 then a7=l end;if a5<a7 then a7=a5 end;if k>a8 then a8=k end;if a4>a8 then a8=a4 end;if l>a9 then a9=l end;if a5>a9 then a9=a5 end;local h,aa,g,min,max=a8-a6+1,a9-a7+1,{},0,0;f(g,h,i-a6+1,j-a7+1,k-a6+1,l-a7+1)f(g,h,k-a6+1,l-a7+1,a4-a6+1,a5-a7+1)f(g,h,a4-a6+1,a5-a7+1,i-a6+1,j-a7+1)for A=1,aa do min,max=nil;for v=1,h do if g[(A-1)*h+v]then if not min then min=v end;max=v end end;s:drawHLine(min+a6-1,max+a6-1,A+a7-1,char,B,C)end end,drawTriangles=function(s,W,X,char,B,C)X=X or 1;if X==1 then for v=1,#W,6 do s:drawTriangle(W[v],W[v+1],W[v+2],W[v+3],W[v+4],W[v+5],char,B,C)end elseif X==2 then local Y,Z,ab,ac,_,a0=W[1],W[2],W[3],W[4]for v=5,#W,2 do _,a0=W[v],W[v+1]s:drawTriangle(Y,Z,ab,ac,_,a0,char,B,C)Y,Z,ab,ac=ab,ac,_,a0 end elseif X==3 then local a1,a2,Y,Z,_,a0=W[1],W[2],W[3],W[4]for v=5,#W,2 do _,a0=W[v],W[v+1]s:drawTriangle(a1,a2,Y,Z,_,a0,char,B,C)Y,Z=_,a0 end end end,fillTriangles=function(s,W,X,char,B,C)X=X or 1;if X==1 then for v=1,#W,6 do s:fillTriangle(W[v],W[v+1],W[v+2],W[v+3],W[v+4],W[v+5],char,B,C)end elseif X==2 then local Y,Z,ab,ac,_,a0=W[1],W[2],W[3],W[4]for v=5,#W,2 do _,a0=W[v],W[v+1]s:fillTriangle(Y,Z,ab,ac,_,a0,char,B,C)Y,Z,ab,ac=ab,ac,_,a0 end elseif X==3 then local a1,a2,Y,Z,_,a0=W[1],W[2],W[3],W[4]for v=5,#W,2 do _,a0=W[v],W[v+1]s:fillTriangle(a1,a2,Y,Z,_,a0,char,B,C)Y,Z=_,a0 end end end,drawEllipse=function(s,i,j,k,l,char,B,C)if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;local ad,ae,af,h,aa,ag,ah=math.pi*2/16,(i+k)/2,(j+l)/2,(k-i)/2,(l-j)/2,1,1;for v=1,17 do local H,I=a(ae+b(ad*v)*h+0.5),a(af+c(ad*v)*aa+0.5)if v>1 then s:drawLine(ag,ah,H,I,char,B,C)end;ag,ah=H,I end end,fillEllipse=function(s,i,j,k,l,char,B,C)if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;local ai,ad,ae,af,h,aa,ag,ah,aj,ak,g=16,math.pi*2/16,(i+k)/2,(j+l)/2,(k-i)/2,(l-j)/2,1,1,k-i+1,l-j+1,{}for v=1,ai+1 do local H,I=a(ae+b(ad*v)*h+0.5),a(af+c(ad*v)*aa+0.5)if v>1 then f(g,aj,ag-i+1,ah-j+1,H-i+1,I-j+1)end;ag,ah=H,I end;for A=1,ak do min,max=nil;for v=1,aj do if g[(A-1)*aj+v]then if not min then min=v end;max=v end end;s:drawHLine(min+i-1,max+i-1,A+j-1,char,B,C)end end,drawArc=function(s,i,j,k,l,al,am,char,B,C)if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;if al>am then local t=al;al,am=am,t end;local ad,ae,af,h,aa,ag,ah=(am-al)/16,(i+k)/2,(j+l)/2,(k-i)/2,(l-j)/2,1,1;for v=1,17 do local H,I=a(ae+b(ad*v-1+al)*h+0.5),a(af-c(ad*v-1+al)*aa+0.5)if v>1 then s:drawLine(ag,ah,H,I,char,B,C)end;ag,ah=H,I end end,drawPie=function(s,i,j,k,l,al,am,char,B,C)if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;if al>am then local t=al;al,am=am,t end;local ad,ae,af,h,aa,ag,ah=(am-al)/16,(i+k)/2,(j+l)/2,(k-i)/2,(l-j)/2,1,1;for v=1,17 do local H,I=a(ae+b(ad*v-1+al)*h+0.5),a(af-c(ad*v-1+al)*aa+0.5)if v>1 then s:drawLine(ag,ah,H,I,char,B,C)end;ag,ah=H,I end;s:drawLine(a(ae+0.5),a(af+0.5),a(ae+b(al)*h+0.5),a(af-c(al)*aa+0.5),char,B,C)s:drawLine(a(ae+0.5),a(af+0.5),a(ae+b(am)*h+0.5),a(af-c(am)*aa+0.5),char,B,C)end,fillPie=function(s,i,j,k,l,al,am,char,B,C)if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;if al>am then local t=al;al,am=am,t end;local ad,ae,af,h,aa,ag,ah,aj,ak,g=(am-al)/16,(i+k)/2,(j+l)/2,(k-i)/2,(l-j)/2,1,1,k-i+1,l-j+1,{}for v=1,17 do local H,I=a(ae+b(ad*v-1+al)*h+0.5),a(af-c(ad*v-1+al)*aa+0.5)if v>1 then f(g,aj,ag-i+1,ah-j+1,H-i+1,I-j+1)end;ag,ah=H,I end;f(g,aj,a(ae+0.5)-i+1,a(af+0.5)-j+1,a(ae+b(al)*h+0.5)-i+1,a(af-c(al)*aa+0.5)-j+1)f(g,aj,a(ae+0.5)-i+1,a(af+0.5)-j+1,a(ae+b(am)*h+0.5)-i+1,a(af-c(am)*aa+0.5)-j+1)for A=1,ak do min,max=nil;for v=1,aj do if g[(A-1)*aj+v]then if not min then min=v end;max=v end end;if min then s:drawHLine(min+i-1,max+i-1,A+j-1,char,B,C)end end end,floodFill=function(s,H,I,char,B,C)if H<s.x1 or I<s.y1 or H>s.x2 or I>s.y2 then return end;local an,ao,ap,aq={H,I},s.buffer[((I-1)*s.width+H)*3-2],s.buffer[((I-1)*s.width+H)*3-1],s.buffer[((I-1)*s.width+H)*3]if ao==char and ap==B and aq==C then return end;while#an>0 do local ar,as=an[#an-1],an[#an]an[#an]=nil;an[#an]=nil;if ar>=s.x1 and as>=s.y1 and ar<=s.x2 and as<=s.y2 then local at,au,av=s.buffer[((as-1)*s.width+ar)*3-2],s.buffer[((as-1)*s.width+ar)*3-1],s.buffer[((as-1)*s.width+ar)*3]if ao==at and ap==au and aq==av then if char or s.overwrite then s.buffer[((as-1)*s.width+ar)*3-2]=char end;if B or s.overwrite then s.buffer[((as-1)*s.width+ar)*3-1]=B end;if C or s.overwrite then s.buffer[((as-1)*s.width+ar)*3]=C end;an[#an+1]=ar-1;an[#an+1]=as;an[#an+1]=ar+1;an[#an+1]=as;an[#an+1]=ar;an[#an+1]=as-1;an[#an+1]=ar;an[#an+1]=as+1 end end end end,drawSurface=function(s,H,I,u)for A=1,u.height do for v=1,u.width do s:drawPixel(v+H-1,A+I-1,u.buffer[((A-1)*u.width+v)*3-2],u.buffer[((A-1)*u.width+v)*3-1],u.buffer[((A-1)*u.width+v)*3])end end end,drawSurfacePart=function(s,H,I,L,M,N,O,u)if L>N then local t=L;L,N=N,t end;if M>O then local t=M;M,O=O,t end;if N<1 or L>u.width or O<1 or M>u.height then return end;if L<1 then L=1 end;if N>u.width then N=u.width end;if M<1 then M=1 end;if O>u.height then O=u.height end;for A=M,O do for v=L,N do s:drawPixel(H+v-L,I+A-M,u.buffer[((A-1)*u.width+v)*3-2],u.buffer[((A-1)*u.width+v)*3-1],u.buffer[((A-1)*u.width+v)*3])end end end,drawSurfaceScaled=function(s,i,j,k,l,u)local H,h,aw,I,aa,ax=0,0,false,0,0,false;if i<=k then H=i;h=k-i+1 else H=k;h=i-k+1;aw=true end;if j<=l then I=j;aa=l-j+1 else I=l;aa=j-l+1;ax=true end;local ay,az,V,aA=h/u.width,aa/u.height;for A=1,aa do for v=1,h do if aw then V=a((h-v+0.5)/ay)+1 else V=a((v-0.5)/ay)+1 end;if ax then aA=a((aa-A+0.5)/az)+1 else aA=a((A-0.5)/az)+1 end;s:drawPixel(H+v-1,I+A-1,u.buffer[((aA-1)*u.width+V)*3-2],u.buffer[((aA-1)*u.width+V)*3-1],u.buffer[((aA-1)*u.width+V)*3])end end end,drawSurfaceRotated=function(s,H,I,aB,aC,aD,u)local cos,sin,aE=b(aD),c(aD),a(math.sqrt(u.width*u.width+u.height*u.height))H,I=H-a(cos*aB-1+sin*aC-1+0.5),I-a(cos*aC-1-sin*aB-1+0.5)for A=-aE,aE do for v=-aE,aE do local aF,aG=a(v*cos-A*sin),a(v*sin+A*cos)if aF>=0 and aF<u.width and aG>=0 and aG<u.height then s:drawPixel(H+v,I+A,u.buffer[(aG*u.width+aF)*3+1],u.buffer[(aG*u.width+aF)*3+2],u.buffer[(aG*u.width+aF)*3+3])end end end end,shader=function(s,y,i,j,k,l)i,j,k,l=i or s.x1,j or s.y1,k or s.x2,l or s.y2;if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;if k<s.x1 or i>s.x2 or l<s.y1 or j>s.y2 then return end;if i<s.x1 then i=s.x1 end;if k>s.x2 then k=s.x2 end;if j<s.y1 then j=s.y1 end;if l>s.y2 then l=s.y2 end;local h,g=k-i+1,{}for A=j,l do for v=i,k do g[((A-j)*h+v-i)*3+1],g[((A-j)*h+v-i)*3+2],g[((A-j)*h+v-i)*3+3]=y(s.buffer[((A-1)*s.width+v)*3-2],s.buffer[((A-1)*s.width+v)*3-1],s.buffer[((A-1)*s.width+v)*3],v,A)end end;for A=j,l do for v=i,k do s.buffer[((A-1)*s.width+v)*3-2],s.buffer[((A-1)*s.width+v)*3-1],s.buffer[((A-1)*s.width+v)*3]=g[((A-j)*h+v-i)*3+1],g[((A-j)*h+v-i)*3+2],g[((A-j)*h+v-i)*3+3]end end end,shift=function(s,H,I,i,j,k,l)i,j,k,l=i or s.x1,j or s.y1,k or s.x2,l or s.y2;if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;if k<s.x1 or i>s.x2 or l<s.y1 or j>s.y2 then return end;if i<s.x1 then i=s.x1 end;if k>s.x2 then k=s.x2 end;if j<s.y1 then j=s.y1 end;if l>s.y2 then l=s.y2 end;local h,g=k-i+1,{}for A=j,l do for v=i,k do if v-H>=1 and A-I>=1 and v-H<=s.width and A-I<=s.height then g[((A-j)*h+v-i)*3+1],g[((A-j)*h+v-i)*3+2],g[((A-j)*h+v-i)*3+3]=s.buffer[((A-I-1)*s.width+v-H)*3-2],s.buffer[((A-I-1)*s.width+v-H)*3-1],s.buffer[((A-I-1)*s.width+v-H)*3]end end end;for A=j,l do for v=i,k do s.buffer[((A-1)*s.width+v)*3-2],s.buffer[((A-1)*s.width+v)*3-1],s.buffer[((A-1)*s.width+v)*3]=g[((A-j)*h+v-i)*3+1],g[((A-j)*h+v-i)*3+2],g[((A-j)*h+v-i)*3+3]end end end}function create(h,aa,char,B,C)local s={}for aH,aI in pairs(r)do s[aH]=aI end;s.width,s.height,s.x1,s.y1,s.x2,s.y2,s.curX,s.curY,s.overwrite,s.buffer=h,aa,1,1,h,aa,1,1,false,{}if char then for v=1,h*aa do s.buffer[v*3-2]=char end end;if B then for v=1,h*aa do s.buffer[v*3-1]=B end end;if C then for v=1,h*aa do s.buffer[v*3]=C end end;return s end;function load(w)local aJ,y={},fs.open(w,"r")for aK in y.readLine do aJ[#aJ+1]=aK end;y.close()local aa=#aJ;if aJ[1]:byte(1)==30 then local h,v=0,1;while v<=#aJ[1]do local char=aJ[1]:byte(v)if char==30 or char==31 then v=v+1 else h=h+1 end;v=v+1 end;local s,B,C,v,V,char,z=create(h,aa)for A=1,aa do v=1;V=1;while v<=#aJ[A]do char=aJ[A]:byte(v)if char==30 then v=v+1;char=aJ[A]:byte(v)z=tonumber(aJ[A]:sub(v,v),16)if z then B=2^z else B=nil end elseif char==31 then v=v+1;char=aJ[A]:byte(v)z=tonumber(aJ[A]:sub(v,v),16)if z then C=2^z else C=nil end else s.buffer[((A-1)*s.width+V)*3-2]=aJ[A]:sub(v,v)s.buffer[((A-1)*s.width+V)*3-1]=B;s.buffer[((A-1)*s.width+V)*3]=C;V=V+1 end;v=v+1 end end;return s elseif aJ[1]:byte(1)==95 then return loadString(aJ[1])else local h=0;for v=1,#aJ do if#aJ[v]>h then h=#aJ[v]end end;local s,z=create(h,aa)for A=1,aa do for v=1,h do z=tonumber(aJ[A]:sub(v,v),16)if z then s.buffer[((A-1)*s.width+v)*3-1]=2^z end end end;return s end end;function loadString(D)local h,aa,G=tonumber(D:sub(2,5),16),tonumber(D:sub(6,9),16),10;local s=create(h,aa)for A=1,aa do for v=1,h do if D:byte(G)~=95 then s.buffer[((A-1)*s.width+v)*3-2]=string.char(tonumber(D:sub(G,G+1),16))end;if D:byte(G+2)~=95 then s.buffer[((A-1)*s.width+v)*3-1]=2^tonumber(D:sub(G+2,G+2),16)end;if D:byte(G+3)~=95 then s.buffer[((A-1)*s.width+v)*3]=2^tonumber(D:sub(G+3,G+3),16)end;G=G+4 end end;return s end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement