The QBasic Forum      Other Subforums, Links and Downloads
 
  << Previous Topic | Next Topic >>Return to Index  

Particle fountain for the fourth

July 4 2008 at 6:59 AM
  (Login T3sl4)
R
from IP address 68.185.180.20

DEFINT A-Z

CONST MaxParticles = 2000, Gravity = 1, WindRes! = 1, MaxVel = 20
MaxTime = 3: MinTime = 2
NumParticles = 2000

TYPE ParticleDefs
Alive AS INTEGER 'Determines wether or not it's alive
PStart AS SINGLE 'Time when particle started (for life)
Duration AS SINGLE 'life time (random)
xPos AS INTEGER 'Current x position
yPos AS INTEGER 'Current y position
zPos AS INTEGER 'Current z position
xVel AS INTEGER 'Current x velocity
yVel AS INTEGER 'Current y velocity
zVel AS INTEGER 'Current z velocity
END TYPE

DIM Particles(MaxParticles) AS ParticleDefs, CurrTime AS SINGLE, Start AS SINGLE, Finish AS SINGLE, Phi AS SINGLE
SCREEN 7, , 1, 0
RANDOMIZE TIMER
ON ERROR GOTO ErrHndlr

StartTime& = TIMER
CurrTime = TIMER - StartTime&

FOR i = 0 TO NumParticles - 1
Particles(i).Alive = 1
Particles(i).PStart = CurrTime
Particles(i).Duration = RND * MaxTime + MinTime
Particles(i).xPos = 0
Particles(i).yPos = 0
Particles(i).zPos = 0
hVel = RND * 40: Phi = RND * 6.283185
Particles(i).xVel = hVel * COS(Phi)
Particles(i).yVel = RND * -30 - 20
Particles(i).zVel = hVel * SIN(Phi)
NEXT

DO
CurrTime = TIMER - StartTime&
x$ = LCASE$(INKEY$)
IF x$ = "," AND NumParticles > 30 THEN NumParticles = NumParticles - 20
IF x$ = "." AND NumParticles < MaxParticles - 50 THEN NumParticles = NumParticles + 20
IF x$ = "a" AND MaxTime > 1 THEN MaxTime = MaxTime - 1
IF x$ = "z" THEN MaxTime = MaxTime + 1
IF x$ = "s" AND MinTime > 0 THEN MinTime = MinTime - 1
IF x$ = "x" THEN MinTime = MinTime + 1
IF x$ = "b" THEN
FOR i = 0 TO NumParticles - 1
Particles(i).Alive = 1
Particles(i).PStart = CurrTime
Particles(i).Duration = RND * MaxTime + MinTime
Particles(i).xPos = 0
Particles(i).yPos = 50
Particles(i).zPos = 0
hVel = RND * 40: Phi = RND * 6.283185
Particles(i).xVel = hVel * COS(Phi)
Particles(i).yVel = RND * -30 - 20
Particles(i).zVel = hVel * SIN(Phi)
NEXT
END IF
IF x$ = "p" THEN
SCREEN , , 0, 0
LOCATE 2, 1: INPUT "Please type valid file name to write to (will not be written if invalid) (Extension is .CRD; please do not use an extension) (File will be overwritten without prompt): ", FileName$
IF NOT (INSTR(FileName$, "?") OR INSTR(FileName$, "*") OR INSTR(FileName$, ".") OR LEN(FileName$) > 8) THEN
OPEN FileName$ + ".CRD" FOR OUTPUT AS #1
PRINT #1, NumParticles
FOR i = 0 TO NumParticles - 1
j = j + 1
IF j = 16 THEN j = 1
x = Particles(i).xPos: y = Particles(i).yPos: z = Particles(i).zPos
WRITE #1, x, y, z, j
NEXT
CLOSE #1
END IF
SCREEN , , 1, 0
END IF

FOR i = 0 TO NumParticles - 1
IF Particles(i).Alive = 0 THEN
Particles(i).Alive = 1
Particles(i).PStart = CurrTime
Particles(i).Duration = RND * MaxTime + MinTime
IF NumParticles > 400 THEN Particles(i).Duration = Particles(i).Duration + 1
Particles(i).xPos = 0
Particles(i).yPos = 0
Particles(i).zPos = 0
Particles(i).xVel = RND * 30 - 15
Particles(i).yVel = RND * -30 - 20
Particles(i).zVel = RND * 30 - 15
END IF
IF Particles(i).Alive = 1 THEN
Particles(i).xVel = Particles(i).xVel / WindRes!
Particles(i).yVel = Particles(i).yVel + Gravity
Particles(i).zVel = Particles(i).zVel / WindRes!
IF Particles(i).yVel > MaxVel THEN Particles(i).yVel = MaxVel
Particles(i).xPos = Particles(i).xPos + Particles(i).xVel
Particles(i).yPos = Particles(i).yPos + Particles(i).yVel
Particles(i).zPos = Particles(i).zPos + Particles(i).zVel
IF Particles(i).PStart + Particles(i).Duration < CurrTime THEN Particles(i).Alive = 0
END IF
NEXT

j = 0
CLS
FOR i = 0 TO NumParticles - 1
j = j + 1
IF j = 16 THEN j = 1
IF Particles(i).Alive = 1 THEN
x& = Particles(i).xPos: y& = Particles(i).yPos: z& = Particles(i).zPos + 500
xScr = 128 * (x& / z&) + 160
yScr = 128 * (y& / z&) + 100
IF xScr > 0 AND yScr > 0 AND xScr < 320 AND ySxr < 200 AND z& > 10 THEN
Dist& = x& * x& + y& * y& + z& * z&
Size = 100000 / Dist&
IF Size > 1 THEN
LINE (xScr, yScr)-(xScr + Size, yScr + Size), j, BF
ELSEIF Size = 1 THEN
LINE (xScr, yScr)-(xScr + Size, yScr + Size), j, B
ELSEIF Size = 0 THEN
PSET (xScr, yScr), j
END IF
END IF
END IF
NEXT
LOCATE 1, 1: PRINT "MaxTime:"; MaxTime; "MinTime:"; MinTime; "Particles:"; NumParticles;
PCOPY 1, 0
IF x$ = CHR$(27) THEN EXIT DO
LOOP

END

ErrHndlr:
RESUME NEXT


 
 Respond to this message   
AuthorReply

(Login The-Universe)
R
70.177.5.114

*Particle fountain for the fourth is so realistic, it set off my smoke alarm. Very nice!

July 4 2008, 8:56 AM 


 
 Respond to this message   

(Login qb432l)
R
74.15.64.191

*Positively festive!

July 4 2008, 7:29 PM 

*

 
 Respond to this message   


(Login PhyloGenesis)
R
71.102.246.240

*Very nice.

July 4 2008, 11:44 PM 

*

 
 Respond to this message   
Current Topic - Particle fountain for the fourth
  << Previous Topic | Next Topic >>Return to Index  

Newbies usually go to www.qbasic.com and click on The QBasic Forum
Forum regulars have their own ways, which include The QBasic Community Forums