Log In  

Pico-8 implementation of Scale2x and Scale3x. Original algorithms by Andrea Mazzoleni

Scale2x:

--[[
sind : sprite index 
sz_x : x size
sz_y : y size
sx    : screen pos x
sy    : screen pos y
alpha: color to make transparent
]]--

function scale2x(sind,sz_x,sz_y,sx,sy,alpha)
 alpha=alpha or 0
 local offx=sind%16
 local offy=flr(sind/16)
 local soffx=offx*8
 local soffy=offy*8
 local sizex=sz_x-1
 local sizey=sz_y-1
 local a,b,c,d,e,f,g,h,i,
        e0,e1,e2,e3,x0,y0

 for y=0,sizey do
  for x=0,sizex do
   e=sget(soffx+x,soffy+y)
   a=e
   b=e
   c=e
   d=e
   f=e
   g=e
   h=e
   i=e

   if y>0 then
    b=sget(soffx+x,soffy+y-1)
   end

   if y<sizey then
    h=sget(soffx+x,soffy+y+1)
   end

   if x>0 then
    d=sget(soffx+x-1,soffy+y)
    if y>0 then
     a=sget(soffx+x-1,soffy+y-1)
    end
    if y<sizey then
     g=sget(soffx+x-1,soffy+y+1)
    end
   end

   if x<sizex then
    f=sget(soffx+x+1,soffy+y)

    if y>0 then
     c=sget(soffx+x+1,soffy+y-1)
    end
    if y<sizey then
     i=sget(soffx+x+1,soffy+y+1)
    end
   end

   e0=e
   e1=e
   e2=e
   e3=e

   if b!=h and d!=f then
    if(d==b) e0=d
    if(b==f) e1=f
    if(d==h) e2=d
    if(h==f) e3=f
   end

   --draw
   x0=sx+x*2
   y0=sy+y*2
   if(e0!=alpha) pset(x0,  y0,  e0)
   if(e1!=alpha) pset(x0+1,y0,  e1)
   if(e2!=alpha) pset(x0,  y0+1,e2)
   if(e3!=alpha) pset(x0+1,y0+1,e3)
  end
 end
end

Scale3x:

--[[
sind : sprite index 
sz_x : x size
sz_y : y size
sx    : screen pos x
sy    : screen pos y
alpha: color to make transparent
]]--

function scale3x(sind,sz_x,sz_y,sx,sy,alpha)
 alpha=alpha or 0
 local offx=sind%16
 local offy=flr(sind/16)
 local soffx=offx*8
 local soffy=offy*8
 local sizex=sz_x-1
 local sizey=sz_y-1
 local a,b,c,d,e,f,g,h,i,
       e0,e1,e2,e3,e4,e5,e6,e7,e8,
       x0,y0

 for y=0,sizey do
  for x=0,sizex do
   e=sget(soffx+x,soffy+y)
   a=e
   b=e
   c=e
   d=e
   f=e
   h=e
   i=e
   g=e

   if y>0 then
    b=sget(soffx+x,soffy+y-1)
   end

   if y<sizey then
    h=sget(soffx+x,soffy+y+1)
   end

   if x>0 then
    d=sget(soffx+x-1,soffy+y)
    if y>0 then
     a=sget(soffx+x-1,soffy+y-1)
    end
    if y<sizey then
     g=sget(soffx+x-1,soffy+y+1)
    end
   end

   if x<sizex then
    f=sget(soffx+x+1,soffy+y)

    if y>0 then
     c=sget(soffx+x+1,soffy+y-1)
    end
    if y<sizey then
     i=sget(soffx+x+1,soffy+y+1)
    end
   end

   e0=e
   e1=e
   e2=e
   e3=e
   e4=e
   e5=e
   e6=e
   e7=e
   e8=e

   if b!=h and d!=f then
    if(d==b) e0=d
    if((d==b and e!=c) or (b==f and e!=a)) e1=b
    if(b==f) e2=f
    if((d==b and e!=g) or (d==h and e!=a)) e3=d
    if((b==f and e!=i) or (h==f and e!=c)) e5=f
    if(d==h) e6=d
    if((d==h and e!=i) or (h==f and e!=g)) e7=h
    if(h==f) e8=f
   end

   --draw
   x0=sx+x*3
   y0=sy+y*3
   if(e0!=alpha) pset(x0,  y0,  e0)
   if(e1!=alpha) pset(x0+1,y0,  e1)
   if(e2!=alpha) pset(x0+2,y0,  e2)
   if(e3!=alpha) pset(x0,  y0+1,e3)
   if(e4!=alpha) pset(x0+1,y0+1,e4)
   if(e5!=alpha) pset(x0+2,y0+1,e5)
   if(e6!=alpha) pset(x0,  y0+2,e6)
   if(e7!=alpha) pset(x0+1,y0+2,e7)
   if(e8!=alpha) pset(x0+2,y0+2,e8)
  end
 end
end
P#23217 2016-06-19 13:56 ( Edited 2016-06-19 18:00)


[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-20 10:10:55 | 0.005s | Q:11