Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: Shockwave on August 27, 2006

Title: Fun idea with a texture..
Post by: Shockwave on August 27, 2006
This is pretty. Hope you like it..

The exe was packed with kkrunchy by ryg^farbrausch


'***
'*** FAST BENDY TEXTURED THING BY SHOCKWAVE ^ DBF
'***

        '#define PTC_WIN
        #Include Once "tinyptc.bi"
       
        CONST   XRES    =   640
        CONST   YRES    =   480
       
        dim shared as UINTEGER BUFFER (XRES * YRES)
       
        CONST   HALFX    =   XRES / 2
        CONST   HALFY    =   YRES / 2

'-------------------------------------------------------------------------
' Define Bendy Storage And Sub
'-------------------------------------------------------------------------

    DIM SHARED BENDY( XRES * YRES ) AS UINTEGER
    DECLARE SUB DO_BENDY()
    dim x,y as uinteger
    dim shared gadd as integer
   
    ' Create Xor texture for test purposes;
   
    for y=0 to yres-1
    for x=0 to xres-1
            BENDY (X+(Y*XRES)) = RGB(X XOR Y , (X XOR Y) shr 1 , (X XOR Y)shr 2)
    next
    next
'-------------------------------------------------------------------------
' Sub Definitions;
'-------------------------------------------------------------------------

     declare sub DBCLEAR()

'-------------------------------------------------------------------------
' Open Screen.
'-------------------------------------------------------------------------

        If( ptc_open( ".:RITUEL:.", XRES, YRES ) = 0 ) Then
        End -1
        End If

DO
   
        DBCLEAR()
        DO_BENDY()
       
LOOP UNTIL INKEY$=CHR$(27)
PTC_CLOSE
END


'-------------------------------------------------------------------------
'Sub to double buffer and clear screen.
'-------------------------------------------------------------------------

SUB DBCLEAR()
    gadd=gadd+4
    PTC_UPDATE@BUFFER(0)
    ERASE BUFFER
END SUB

'-------------------------------------------------------------------------
'Sub to do bendy effect in middle of the screen.
'-------------------------------------------------------------------------


SUB DO_BENDY()
    DIM AS UINTEGER X,Y,STI,X2
   
    DIM AS DOUBLE I_STT,I_END,I_INTR,I_INTR2
   
    FOR Y=0 TO YRES-1
       
        I_STT=100+(30*SIN((Y+gadd)/43)+20*COS((Y+gadd)/33)+49*COS((Y+gadd)/73))
       
        STI=INT(I_STT)
       
        I_INTR=halfx/(HALFX - STI)
        I_END = XRES-1
        I_STT=0
        X2=XRES-STI
    FOR X=STI+1 TO HALFX
       
         BUFFER(X+(Y*XRES))=BENDY(((I_STT))+(Y*XRES))
         BUFFER(X2+(Y*XRES))=BENDY(((I_END))+(Y*XRES))
         
         I_STT = I_STT + I_INTR
         I_END = I_END - I_INTR
         X2=X2-1


    NEXT
    NEXT
END SUB
Title: Re: Fun idea with a texture..
Post by: MrP on August 27, 2006
Sweet, like the effect, and the texture's nice to seeing how its created procedurally.... Nice Job....
Title: Re: Fun idea with a texture..
Post by: relsoft on August 28, 2006
cool!!! Sexy!!!
Title: Re: Fun idea with a texture..
Post by: DrewPee on August 28, 2006
Thats absolutely wicked code - so small and so powerfull!
Well done again Shockwave!

DrewPee
Title: Re: Fun idea with a texture..
Post by: Shockwave on August 28, 2006
Thanks peeps :)

There is a silly optimisation that I missed, you can remove 4 multiplys and replace with 1 reciprocal in the DO_BENDY sub. The statements;

Y*XRES

Can be precalculated with a #define to save a little time. Probably the interpolations can be sped up a little bit too.

This looks great with a logo btw.