Shape Ribbon - PlayBASIC Demo

This demo draws a flowing, snake-like ribbon that appears to move toward the camera, creating a simple 3D illusion using only 2D shapes.

It works by drawing many circular shapes (rings) in a line, stretching off into the distance. Each ring is positioned using sine and cosine waves, which makes the path curve and twist in a smooth, organic way.

To fake depth, the rings are scaled and moved based on their distance from the camera. Rings that are “far away” are smaller and closer together, while rings that are “near” are larger and spread out. This gives the impression of perspective, like looking down a tunnel.

Each ring is also slightly stretched and rotated, which helps turn the stack of circles into something that looks more like a twisting ribbon or snake.

Finally, the colours are adjusted based on distance, fading into the background as they move further away. This adds to the depth effect and helps blend everything together visually.

The result is a continuous stream of shapes that feels like it’s flowing through 3D space, even though it’s all just 2D drawing tricks.






PlayBASIC Code:
; PROJECT : Shape_Ribbon
; AUTHOR  : Kevin Picone
; CREATED : 25/07/2008
; EDITED  : 13/04/2026
; ---------------------------------------------------------------------

    setfps 50

    Colour_Offset =0

    screen=NewFxIMage(GetScreenWidth(),GetScreenHeight())
    
    rings        =1000
    RingSize#=100

    FarDepth#    =30000
    NearDepth#    =100

    me=NewConvexShape(RingSize#,32)

    Edges=GetShapeEdges(me,0)*rings

    ;shapedebug me,true

    ClsColour=rgb(20,30,50)

    mx=getscreenwidth()/2
    my=getscreenheight()/2

        
    Do

        rendertoimage Screen


        CLs ClsColour
    
        ink $ffffff

;        thisrgb=rgb(50,20,210)

        zstep#=(NearDepth#-FarDepth#)/Rings
            
            Scale_Step# += 1.1
            inkmode 1+32

            Colour_Offset =  -int(Scale_Step#)

            projection#=400
        lockbuffer        
            For lp=0 to rings-1
                
                offset =  Colour_Offset +lp ;(rings-lp)
                
                x#=cos(angle#+lp*2)*455
                y#=sin(angle#+lp)*355

                x#+=cos(angle2#+lp*4)*255
                y#+=sin(angle2#+lp*2)*155

                Scale# = lp  + mod(Scale_Step#,1.0)

                z#=FarDepth#+(Scale#*zstep#)

                if z#<NearDepth# then continue

                pbyz# =projection#/z#

                Scale# = (RingSize# *pbyz#) / RingSize#

                rotateshapexy me,Angle2#+(offset/2),Scale#*1.25,Scale#*(3+1*sin(offset))

                sx#=mx+(x#*pbyz#)
                sy#=my+(y#*pbyz#)
                
                ThisRGB = offset * $010203
                ThisRGB = rgbdepthcue(ThisRgb,ClsColour, z#,NearDepth#,FarDepth#)  
            
                ink ThisRGB
                DrawShape me,sx#,sy#,2
            next
        unlockbuffer        

        rendertoscreen
        setcursor 0,0
        ink rgb(255,255,255)
        inkmode 1


        if LeftKey()=false and mousebutton()=0
            angle#=wrapangle(Angle#,1.5)
            angle2#=wrapangle(Angle2#,3)

        endif

        drawimage screen,0,0,false
        print fps()
        print edges
        
        Sync    
    loop