﻿-- rgbplasma
-- by rez

local a,cr,cg,cb,cw=
    127,{},{},{},{}

function _init()
    cls()
    for i=0,127 do
        cr[i]=sget(i,0)
        cg[i]=sget(i,1)
        cb[i]=sget(i,2)
        cw[i]=sget(i,3)
    end
end

function _draw()
    local a2=a*2
    for x=3,123,3 do
        local x2=x/2048
        for y=3,123,3 do
            local y2=y/1024
            local v1,v2=
                256+192*sin(y2+a2),
                sin(a-x2+y2)
            local r,g,b=
                56*cos(a2+x/v1+v2),
                48*sin((x+y)/v1*v2),
                40*cos((x*v2-y)/v1)
            pset(x,y,cr[flr(56+r)])
            pset(x+1,y,cg[flr(48-g)])
            pset(x,y+1,cb[flr(40+b)])
            pset(x+1,y+1,cw[flr(32-r+g)])
        end
    end
    --if(a==0) extcmd "rec"
    a+=0.0025
    if a>1 then
        a=0
        --extcmd "video"
    end
    --rectfill(0,0,40,6,1)
    --print("cpu:"..stat(1),1,1,12)
end
