Animation by sprites

There has been a spate of sightings of this illusion on YouTube, TikTok etc. I fancied coding it. Using LB's drawing commands it is quite easy, but the result has visible drawing delays on my machine, Instead I thought I'd do it with sprites. These are made in a separate LB program as BMPs and then converted to sprites. A pretty background of where I am at present makes it look more interesting. By saving each frame I can assemble an animated GIF which I can use, without LB, on my website or to email to a friend.

Adding variations is easier- starting with one ball and then adding a new one each revolution, altering number of balls, rotating each sprite... all good fun.

Code in LB

    '   I created the sprites separately as bmp's then used LB's sprite converter.


    WindowWidth  =580
    WindowHeight =530

    open "Sprite demo" for graphics_nsb as #wg

    #wg "trapclose quit"

    loadbmp "background", "background2.bmp" '   You can choose any image as background.
    #wg     "background    background"

    for j =1 to 8
        loadbmp "ball" +str$( j), "ball" +str$( j) +"Sprite.bmp"
        #wg "addsprite ballSpr" +str$( j) +" ball" +str$( j)
        #wg "centersprite ballSpr" +str$( j)
    next j

        i   =1

            for k =1 to 8   '                       '   for each of eight diagonal
                th      =( 22.5 *( i +k))             '   th =angle of diagonal path
                r       =170 *sinRad( i *4.5 +22.5 *k)        '   sinusoidal change to radius

                xSc     =int( 280 +r *sinRad( 22.5 *k))
                ySc     =int( 250 -r *cosRad( 22.5 *k))
                #wg "spritexy ballSpr" +str$( k) +" "; xSc; " "; ySc
                #wg "drawsprites"
                'calldll #kernel32, "Sleep", 100 as long, ret as void
            next k

            calldll #kernel32, "Sleep", 50 as long, ret as void
            i   =i +1
            ' save each image to assemble a animated GIF to use elsewhere
            '#wg "getbmp scr 1 1 580 530"
            'bmpsave "scr", "aniBalls" +right$( "00000" +str$( i), 5) +".bmp"
        loop until i >10000


    function sinRad( t)
        sinRad =sin( t *3.14159265 /180)
    end function

    function cosRad( t)
        cosRad =cos( t *3.14159265 /180)
    end function

    sub quit h$
        close #h$
    end sub