News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Vortex

Started by kevin, September 21, 2009, 12:59:31 PM

Previous topic - Next topic

kevin

 Vortex

 Spinning vortex thing :)


 
PlayBASIC Code: [Select]
 Type tPOsition
x#
y#
Size
EndType


Size=500
Dim Vortex(Size) as tPOsition


TotalDegrees#=360*10
RadiusMax=500
RadiusMin=10

For lp=0 to Size
Angle#=(TotalDegrees#/Size)*lp
Angle#=(TotalDegrees#/Size)*lp
Radius#=RadiusMin+(((RadiusMax-RadiusMin)/TotalDegrees#)*Angle#)
InitLink(lp,Angle#,Radius#)
next



FramesPerTransistion=20

; Setfps 75


TicksPerTransistion = 250

StartTime =Timer()
FrameStartTime =Timer()
FrameEndTime =FrameStartTime+TicksPerTransistion

; Setfps 10
Do
Cls 0

CurrentTime=Timer()

passes=0
While CurrentTime=>FrameEndTime

FrameStartTime =FrameStartTime+TicksPerTransistion
FrameEndTime =FrameStartTime+TicksPerTransistion
CopyArrayCells Vortex(),Size-1,-1,Vortex(),Size,-1,(Size)
InitLink(0,0,RadiusMin)
inc passes
EndWHile

Scaler#=Float(CurrentTime-FrameStartTime)/TicksPerTransistion
DrawVortex(Scaler#)

Sync
loop





Function InitLink(INdex,Angle#,Radius#)

sw=getScreenWidth()/2
sh=getScreenHeight()/2

Vortex(Index).x#=sw+Cos(Angle#)*Radius#
Vortex(Index).y#=sh+Sin(Angle#)*Radius#
Vortex(Index).size=rndrange(10,20)

EndFunction

Function DrawVortex(Scaler#)

Size=GetArrayElements(Vortex().Tposition,1)

x1#=Vortex(0).x#
y1#=Vortex(0).y#

Radius=10

lockbuffer
for lp=1 to Size

x2#=Vortex(lp).x#
y2#=Vortex(lp).y#

dx#=x2#-x1#
dy#=y2#-y1#

x#=x1#+(dx#*Scaler#)
y#=y1#+(dy#*Scaler#)

circle x#,y#,radius,true

; line x1#,y1#,x2#,y2#

x1#=x2#
y1#=y2#

next

unlockbuffer


EndFunction







  This is the screen shot version..

PlayBASIC Code: [Select]
 Type tPOsition
x#
y#
Size
EndType


Size=1000
Dim Vortex(Size) as tPOsition


TotalDegrees#=360*10
RadiusMax=500
RadiusMin=10

For lp=0 to Size
Angle#=(TotalDegrees#/Size)*lp
Angle#=(TotalDegrees#/Size)*lp
Radius#=RadiusMin+(((RadiusMax-RadiusMin)/TotalDegrees#)*Angle#)
InitLink(lp,Angle#,Radius#)
next




TicksPerTransistion = 250

StartTime =Timer()
FrameStartTime =Timer()
FrameEndTime =FrameStartTime+TicksPerTransistion

sw=getScreenwidth()
sh=GetSCreenHeight()
Screen=NewFxImage(sw,sh)


Do
rendertoimage Screen



c1=rgb(200,200,200)
c2=rgbfade(c1,50)
inkmode 1
shadebox 0,0,sw,sh,c1,c2,c1,c2

CurrentTime=Timer()
While CurrentTime=>FrameEndTime
FrameStartTime =FrameStartTime+TicksPerTransistion
FrameEndTime =FrameStartTime+TicksPerTransistion
CopyArrayCells Vortex(),Size-1,-1,Vortex(),Size,-1,(Size)
InitLink(0,0,RadiusMin)
EndWHile

Scaler#=Float(CurrentTime-FrameStartTime)/TicksPerTransistion

ink Rgb(100,100,210)

inkmode 1+32 ;2048
DrawVortex(Scaler#)
rendertoscreen

drawimage Screen,0,0,0
Sync
loop





Function InitLink(INdex,Angle#,Radius#)

sw=getScreenWidth()/2
sh=getScreenHeight()/2

Vortex(Index).x#=sw+Cos(Angle#)*Radius#
Vortex(Index).y#=sh+Sin(Angle#)*Radius#

dist#=getdistance2d(sw,sh,Vortex(Index).x#,Vortex(Index).y#)

Vortex(Index).size=5+(Radius#/22)

EndFunction

Function DrawVortex(Scaler#)

Size=GetArrayElements(Vortex().Tposition,1)

x1#=Vortex(0).x#
y1#=Vortex(0).y#
r1#=Vortex(0).Size

lockbuffer
for lp=1 to Size

x2#=Vortex(lp).x#
y2#=Vortex(lp).y#
r2#=Vortex(lp).Size


dx#=x2#-x1#
dy#=y2#-y1#

x#=x1#+(dx#*Scaler#)
y#=y1#+(dy#*Scaler#)

Radius=r1#+((r2#-r1#)*Scaler#)

circle x#,y#,radius,true


x1#=x2#
y1#=y2#
r1#=r2#

next

unlockbuffer


EndFunction





ATLUS