• Welcome to Dark Bit Factory & Gravity.
 

Twister with 8 segments

Started by Shockwave, June 28, 2009

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Shockwave

Don't take it too serious, it was coded in 40 mins :)


'
' Mister Twister Code Started 19:24pm 28/06/09 Finished 20:10 28/06/09
' Fast code, be kind :-) I know it's ugly :-p
' By Shockwave.
'
'===============================================================================

    #INCLUDE "TINYPTC_EXT.BI"
    #INCLUDE "WINDOWS.BI"

'-------------------------------------------------------------------------------   
'   SCREEN SETUP;   
'-------------------------------------------------------------------------------

    CONST   XRES    =    800
    CONST   YRES    =    600
   
    DIM SHARED AS INTEGER HALFX   
    DIM SHARED AS INTEGER HALFY
   
    HALFX=XRES/2
   
    DIM SHARED AS DOUBLE RAD2DEG
    DIM SHARED AS DOUBLE RAD2DEG2
    RAD2DEG =3.14/180
    RAD2DEG2=3.14/180
'-------------------------------------------------------------------------------
'   SET UP THE SCREEN.
'-------------------------------------------------------------------------------

    DIM SHARED AS UINTEGER BUFFER        ( XRES * YRES ):        ' SCREEN BUFFER
   
    DECLARE SUB TWISTER()
    DECLARE SUB RENDERLINE(BYVAL YP AS INTEGER, BYVAL XP AS INTEGER, BYVAL SLICE AS INTEGER, BYVAL TC AS UINTEGER)
'-------------------------------------------------------------------------------
'   SET UP THE SCREEN.
'-------------------------------------------------------------------------------

    PTC_ALLOWCLOSE(0)   
    PTC_SETDIALOG(1,"WWW.DBFINTERACTIVE.COM"+CHR$(13)+"FULL SCREEN?",0,1)               
    IF (PTC_OPEN("Coded by Shockwave",XRES,YRES)=0) THEN
    END-1
    END IF   

'-------------------------------------------------------------------------------
'   MAIN LOOP
'-------------------------------------------------------------------------------
    DIM SHARED AS DOUBLE OLD,DELTA,ADDMOVE
    ADDMOVE=0.0
WHILE(GETASYNCKEYSTATE(VK_ESCAPE)<> -32767 and PTC_GETLEFTBUTTON=FALSE) 
    OLD=TIMER

    TWISTER()
    PTC_UPDATE@BUFFER(0)
    SLEEP 1
    ERASE BUFFER
    DELTA=(TIMER-OLD)*150
    ADDMOVE=ADDMOVE+DELTA
WEND
    EXITPROCESS(0)
END

SUB TWISTER()
   
DIM AS INTEGER Y,X1,X2,X3,X4,X5,X6,X7,X8
DIM AS INTEGER PNR
DIM AS DOUBLE COUNTER,SV,PULSE
COUNTER=ADDMOVE

FOR Y=0 TO YRES-1

    SV=149*SIN((Y-COUNTER)*(RAD2DEG*.3))
    PULSE=110+60*SIN((Y+COUNTER)*RAD2DEG2*.15)

    X1=HALFX+(PULSE*SIN((SV+COUNTER)*RAD2DEG))
    X2=HALFX+(PULSE*SIN((SV+COUNTER+45)*RAD2DEG))
    X3=HALFX+(PULSE*SIN((SV+COUNTER+90)*RAD2DEG))
    X4=HALFX+(PULSE*SIN((SV+COUNTER+135)*RAD2DEG))
    X5=HALFX+(PULSE*SIN((SV+COUNTER+180)*RAD2DEG))
    X6=HALFX+(PULSE*SIN((SV+COUNTER+215)*RAD2DEG))
    X7=HALFX+(PULSE*SIN((SV+COUNTER+260)*RAD2DEG))
    X8=HALFX+(PULSE*SIN((SV+COUNTER+295)*RAD2DEG))
   


    IF X2>X1 THEN
        SLICE=X2-X1
        RENDERLINE(Y,X1,SLICE,RGB(SLICE,SLICE*.5,SLICE*.2))
    END IF

    IF X3>X2 THEN
        SLICE=X3-X2
        RENDERLINE(Y,X2,SLICE,RGB(SLICE*.5,SLICE*.2,SLICE))
    END IF

    IF X4>X3 THEN
        SLICE=X4-X3
        RENDERLINE(Y,X3,SLICE,RGB(SLICE*.2,SLICE,SLICE*.5))
    END IF

    IF X5>X4 THEN
        SLICE=X5-X4
        RENDERLINE(Y,X4,SLICE,RGB(SLICE*.2,SLICE*.5,SLICE))
    END IF

    IF X6>X5 THEN
        SLICE=X6-X5
        RENDERLINE(Y,X5,SLICE,RGB(SLICE,SLICE*.5,SLICE*.2))
    END IF

    IF X7>X6 THEN
        SLICE=X7-X6
        RENDERLINE(Y,X6,SLICE,RGB(SLICE*.5,SLICE*.2,SLICE))
    END IF

    IF X8>X7 THEN
        SLICE=X8-X7
        RENDERLINE(Y,X7,SLICE,RGB(SLICE*.2,SLICE,SLICE*.5))
    END IF

    IF X1>X8 THEN
        SLICE=X1-X8
        RENDERLINE(Y,X8,SLICE,RGB(SLICE*.2,SLICE*.5,SLICE))
    END IF




    PNR+=XRES
    COUNTER-=.035
NEXT
END SUB



SUB RENDERLINE(BYVAL YP AS INTEGER, BYVAL XP AS INTEGER, BYVAL SLICE AS INTEGER, BYVAL TC AS UINTEGER)
DIM AS UINTEGER PTR PP
                    PP=@BUFFER((YP*XRES)+XP)
                    asm
                    mov eax,dword ptr[TC]
                    mov ecx, [slice]
                    mov edi, [PP]
                    rep stosd
                    end asm       
END SUB

Shockwave ^ Codigos
Challenge Trophies Won:

hellfire

I guess the effect would be more convincing if the radius becomes smaller at places with stronger twist.
Challenge Trophies Won:

Moroboshisan

COOL!!!  :clap:

very smooth! It would be nice to have some random spin-ups or changing "rotating" direction...

are you planning to release something in the near future? How about jelly cubes falling from top and bouncing on top of each other?? ;)

:cheers:

Shockwave

Quote from: hellfire on June 28, 2009
I guess the effect would be more convincing if the radius becomes smaller at places with stronger twist.

Yes, that would work nice.

Quote from: Moroboshisan on June 28, 2009
are you planning to release something in the near future? How about jelly cubes falling from top and bouncing on top of each other?? ;)
:cheers:

The next thing I do is going to be a textmode demo to be released at SUndown in September I think.. I was just killing time with this, please feel free to take it and use it :)
Shockwave ^ Codigos
Challenge Trophies Won:

DrewPee

I like that Shockwave, I will now disect it - thanks for the code! ;)

DrewPee
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Shockwave

Shockwave ^ Codigos
Challenge Trophies Won:

benny!

[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

ferris

Twisters are probably my all-time favorite oldschool effects :)

I hope to achieve something like this on the C-64, but that's been put on hold to finish 3 YUP prods coming out this month...;)

Anyways very nice and welldone!! You pulled it off fantastically :)
http://iamferris.com/
http://youth-uprising.com/

Where the fun's at.
Challenge Trophies Won:

Shockwave

It wasnt bad for 40 mins work :)
Shockwave ^ Codigos
Challenge Trophies Won:

spitfire

Hmm why am I now in the mood for softserve ice-cream :P

Shockwave

Shockwave ^ Codigos
Challenge Trophies Won:

Clyde

how would you texture those beauties? even if its using xor as an example ;)
As im like Ferris, love twistyness :)

Awesome dude,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won: