Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: Shockwave on June 28, 2009
-
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
-
I guess the effect would be more convincing if the radius becomes smaller at places with stronger twist.
-
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:
-
I guess the effect would be more convincing if the radius becomes smaller at places with stronger twist.
Yes, that would work nice.
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 :)
-
I like that Shockwave, I will now disect it - thanks for the code! ;)
DrewPee
-
Happy disecting. ^-^
-
N1!
-
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 :)
-
It wasnt bad for 40 mins work :)
-
Hmm why am I now in the mood for softserve ice-cream :P
-
Yum!
-
how would you texture those beauties? even if its using xor as an example ;)
As im like Ferris, love twistyness :)
Awesome dude,
Clyde.