option explicit
const OUTFOLDER="Frames"
const PI=3.14159265358979
dim x,y,t,xx,yy,tmpX,tmpY,oPic,oFS,filename,clip
dim StartFrame,EndFrame,FrameWidth,FrameHeight
dim xL,xR,yT,yB,xW,yH,r,g,b
dim offsetx,offsety,FrameCount,theta
set oFS=createobject("scripting.filesystemobject")
set oPic=createObject("ASPPicture.Picture")

drawFrames
cleanup

sub drawFrames()
    clip=3
    select case Clip
    case 1
        setValues 0,16,256,256,-pi,pi,-pi,pi
        offsetx=0
        offsety=0
    case 2
        setValues 0,64,256,256,-2*pi,2*pi,-2*pi,2*pi
        offsetx=pi/2
        offsety=pi/2
    case 3
        setValues 0,64,256,256,-6*pi,5*pi,-6*pi,5*pi
        offsetx=pi/2
        offsety=pi/2
    case 4
        setValues 0,128,256,256,-2*pi,2*pi,-2*pi,2*pi
        offsetx=0
        offsety=0
    end select

    if not oFS.FolderExists(OUTFOLDER) then oFS.CreateFolder OUTFOLDER
    if not oFS.FolderExists(OUTFOLDER & "\" & setDigits(Clip,3)) then oFS.CreateFolder OUTFOLDER & "\" & setDigits(Clip,3) 

    FrameCount=EndFrame-StartFrame
    for t=StartFrame to EndFrame
        oPic.Init FrameWidth,FrameHeight
        for x=0 to FrameWidth-1
            for y=0 to FrameHeight-1
                theta=8*PI*t/FrameCount
                tmpX=(x-128)*cos(theta) - (y-128)*sin(theta)
                tmpY=(x-128)*sin(theta) + (y-128)*cos(theta)
                'wscript.echo tmpX & "," & tmpY & ": " & xx & "," & yy
                xx=xL+((tmpX-128)/FrameWidth)*xW
                yy=yT-((tmpY-128)/FrameHeight)*yH
                r=64*sin(xx)+64
                g=64*sin(yy)+64
                b=48*cos(xx+yy)+32
                if r<0 or r>255 then r=0
                if g<0 or g>255 then g=0
                if b<0 or b>255 then b=0
                
                oPic.PutPoint x, y, RGB(r,g,b)
            next
        next
        oPic.SaveFile OUTFOLDER & "\" & setDigits(Clip,3) & "\" & setDigits(t,4) & ".png"
    next
end sub

sub calcRGBx(byRef r, byRef g, byRef b,byVal pClip)
    if pClip=1 then
                tmpX=(x-128)*cos(theta) - (y-128)*sin(theta)
                tmpY=(x-128)*sin(theta) + (y-128)*cos(theta)
                'wscript.echo tmpX & "," & tmpY & ": " & xx & "," & yy
                theta=2*PI*t/FrameCount
                xx=xL+(tmpX/FrameWidth)*xW
                yy=yT-(tmpY/FrameHeight)*yH
                r=64*sin(xx)+64
                g=64*sin(yy)+64
                b=0
                if r<0 then r=0
                if r>255 then r=255
                if g<0 then g=0
                if g>255 then g=255
    elseif pClip=2 then
                theta=8*PI*t/FrameCount
                tmpX=(x-128)*cos(theta) - (y-128)*sin(theta)
                tmpY=(x-128)*sin(theta) + (y-128)*cos(theta)
                'wscript.echo tmpX & "," & tmpY & ": " & xx & "," & yy
                xx=xL+((tmpX)/FrameWidth)*xW
                yy=yT-((tmpY)/FrameHeight)*yH
                r=64*sin(xx)+64
                g=64*sin(yy)+64
                b=48*sin(2*pi*t/Framecount)
                if r<0 or r>255 then r=0
                if g<0 or g>255 then g=0
                if b<0 or b>255 then b=0
    elseif pClip=3 then
                theta=8*PI*t/FrameCount
                tmpX=(x-128)*cos(theta) - (y-128)*sin(theta)
                tmpY=(x-128)*sin(theta) + (y-128)*cos(theta)
                'wscript.echo tmpX & "," & tmpY & ": " & xx & "," & yy
                xx=xL+((tmpX-128)/FrameWidth)*xW
                yy=yT-((tmpY-128)/FrameHeight)*yH
                r=64*sin(xx)+64
                g=64*sin(yy)+64
                b=48*cos(xx+yy)+32
                if r<0 or r>255 then r=0
                if g<0 or g>255 then g=0
                if b<0 or b>255 then b=0
    elseif pClip=4 then
                xx=xL+(x/FrameWidth)*xW
                yy=yT-(y/FrameHeight)*yH
                g=abs(sin(PI*(t+1)/(FrameCount+2)))
                b=abs((sin((yy-sin(xx^2))+0)))
                r=abs((cos((xx-cos(yy^2))+0)))
                g=cInt( (((g)*(r+b)*96)) mod 255)
                r=cInt(r*32)
                b=cInt(b*192)
    end if
end sub

sub cleanup()
    set oFS=nothing
    set oPic=nothing
end sub

sub setValues(start_frame,end_frame,frame_width,frame_height,left,right,bottom,top)
    StartFrame=start_frame
    EndFrame=end_frame
    FrameWidth=frame_width
    FrameHeight=frame_height
    xL=left
    xR=right
    yB=bottom
    yT=top
    xW=xR-xL
    yH=yT-yB
end sub

function setDigits(pVal,pDigits)
    dim strVal
    strVal=pVal
    setDigits=string(pDigits-len(strVal),"0") & strVal
end function
