Author Topic: Particle Fountain  (Read 1079 times)

0 Members and 1 Guest are viewing this topic.

SierraKen

• Forum Resident
• Posts: 1454
Particle Fountain
« on: August 26, 2020, 11:23:09 pm »
It doesn't use gravity, so it's sort of a fake particle fountain, but I think it's a good example of particle fluid. You might notice that around most of this code is from my Christmas Lights. lol

Code: QB64: [Select]
1. SCREEN _NEWIMAGE(1200, 800, 32)
2. DIM xx(200), yy(200)
3. DIM cc(300)
4. _TITLE "Fountain"
5. start:
6. tt = 2
7. t2 = 1
8. FOR a = 1 TO 200
9.     xx(a) = RND * 1200
10.     yy(a) = RND * 800
11.     c = INT(RND * 2) + 1
12.     IF c = 1 THEN cc(a) = _RGB32(83, 188, 255)
13.     IF c = 2 THEN cc(a) = _RGB32(177, 183, 255)
14.
15.
16. x2 = 700: y2 = 250
17. x3 = 500: y3 = 250
18.     _LIMIT 15
19.     a\$ = INKEY\$
20.     IF a\$ = CHR\$(27) THEN END
21.     t2 = t2 + 5
22.     FOR amount = 1 TO 200
23.         FOR t = 359 + t2 TO t2 STEP -1
24.             tt = tt + 1.75
25.             'tt = tt + .25
26.             x = (SIN(t) * (90 - tt)) + xx(amount)
27.             y = (COS(t) * tt) + yy(amount)
28.             IF x < 500 OR x > 700 OR y < 250 OR y > 600 THEN
29.                 GOTO skip:
30.             PSET (x, y), cc(amount)
31.             skip:
32.             mm = mm + 1
33.             IF mm < 100 THEN GOTO skip2:
34.             mm = 1
35.             mmm = mmm + 1
36.             IF mmm > 180 THEN mmm = 1
37.             xx2 = (RND * 7) + 3
38.             yy2 = (RND * 13) + 6
39.             xx3 = (RND * 7) + 3
40.             yy3 = (RND * 13) + 6
41.
42.             x2 = x2 + xx2
43.             y2 = y2 + yy2
44.             x3 = x3 - xx3
45.             y3 = y3 + yy3
46.             IF y2 > 600 THEN y2 = 250: x2 = 700
47.             IF y3 > 600 THEN y3 = 250: x3 = 500
48.
49.             PSET (x2, y2), _RGB32(127, 255, 127)
50.             PSET (x3, y3), _RGB32(127, 255, 127)
51.
52.             xx4 = (RND * 30) - 30
53.             yy4 = (RND * 40) - 40
54.             xx5 = (RND * 30) - 30
55.             yy5 = (RND * 40) - 40
56.
57.             xx6 = (RND * 30) - 30
58.             yy6 = (RND * 40) - 40
59.             xx7 = (RND * 30) - 30
60.             yy7 = (RND * 40) - 40
61.
62.             PSET ((SIN(mmm) * 90) + 500 + xx4, (COS(mmm * 2) * -90) + 175 + yy4), _RGB32(127, 255, 127)
63.             PSET ((SIN(mmm) * 90) + 700 + xx5, (COS(mmm * 2) * -90) + 175 + yy5), _RGB32(127, 255, 127)
64.
65.             PSET ((SIN(mmm / 2) * 90) + 500 + xx6, (COS(mmm) * -90) + 250 + yy6), _RGB32(127, 255, 127)
66.             PSET ((SIN(mmm / 2) * 90) + 700 + xx7, (COS(mmm) * -90) + 250 + yy7), _RGB32(127, 255, 127)
67.
68.
69.             skip2:
70.         NEXT t
71.         tt = 2
72.     NEXT amount
73.     LINE (500, 250)-(700, 600), _RGB32(127, 255, 127), B
74.     m = m + 1
75.     IF m = 200 THEN m = 0: GOTO start:
76.

Unseen Machine

• Forum Regular
• Posts: 158
• Make the game not the engine!
Re: Particle Fountain
« Reply #1 on: August 27, 2020, 04:57:52 am »
Hi @SierraKen

I LOVE paritcle engines! I ran your code and was surprised to see an actual fountain! My ind melts trying to unerstand math like that!

Here's little demo of ine for ya, just move the mouse around.

Code: QB64: [Select]
1.
2. GDK_Screen_SetRes GameScreen&, 800, 600
3.
4. DIM Emitter AS Emitter, Particle(250) AS Particle, Mouse(1) AS MouseState
5.
6.
7.   _LIMIT 60
8.
9.   GDK_Mouse_GetState Mouse(0)
10.   GDK_Emitter_New Emitter, Mouse(0).X, Mouse(0).Y, RND * (50), 0, 8 * ATN(1), .5, 1, .1, 3
11.   GDK_Particles_Spawn Emitter, Particle(), 250, _RGB(RND * (255) + 1, RND * (255) + 1, RND * (255) + 1), _RGB(0, 0, 5), RND * (2)
12.   GDK_Particles_Draw Particle(), 250
13.   GDK_Particles_Update Particle(), 250
14.
15.
16. REM \$INCLUDE:'UnseenGDK.bm'

Unseen

_vince

• Seasoned Forum Regular
• Posts: 422
Re: Particle Fountain
« Reply #2 on: August 27, 2020, 09:54:28 am »
Do you have the bm file or do I need Steve's library to compile it?

SMcNeill

• QB64 Developer
• Forum Resident
• Posts: 3972
Re: Particle Fountain
« Reply #3 on: August 27, 2020, 11:08:39 am »
Do you have the bm file or do I need Steve's library to compile it?

That's Unseen's GDK Library, not mine.  As far as I know, it doesn't rely on any of my libraries.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Unseen Machine

• Forum Regular
• Posts: 158
• Make the game not the engine!
Re: Particle Fountain
« Reply #4 on: August 27, 2020, 12:43:41 pm »
@ Vince, good point! i kinda overlooked that! I need to try see if i can merge mine with stxaxtics' collision engine, then it would be COOL!

Unseen

EDIT :

Here's my attempt at fire...

Code: QB64: [Select]
1. '// Fire v.01
2.
3. PMax& = 100000
4.
5. DIM Mouse(1) AS MouseState, kb(1) AS KeyBoardState
6. DIM Emitter AS Emitter, Particle(PMax&) AS Particle
7.
8. GDK_Screen_SetRes MainScreen&, 800, 600
9.
10.
11.   _LIMIT 30
12.
13.   FOR x% = 350 TO 450
14.     GDK_Emitter_New Emitter, x%, 600, RND * (10) + 10, 0, 0, 2, 5, .5, 5
15.     GDK_Particles_Spawn Emitter, Particle(), PMax&, _RGB32(RND * (255) + 150, 0, 0), _RGB(0, RND * (5) + 2, 0), 2
16.
17.   GDK_Particles_Draw Particle(), PMax&
18.   GDK_Particles_Update Particle(), PMax&
19.
20.
21.
22.
23.
24. REM \$INCLUDE:'UnseenGDK.bm'
« Last Edit: August 27, 2020, 01:26:29 pm by Unseen Machine »

SierraKen

• Forum Resident
• Posts: 1454
Re: Particle Fountain
« Reply #5 on: August 27, 2020, 01:33:20 pm »
Awesome examples Unseen! I'm glad you like my fountain.

SierraKen

• Forum Resident
• Posts: 1454
Re: Particle Fountain
« Reply #6 on: August 27, 2020, 01:44:36 pm »
Oh, and the math equations I really don't understand myself either, but I know what works. :)

bplus

• Global Moderator
• Forum Resident
• Posts: 8053
• b = b + ...
Re: Particle Fountain
« Reply #7 on: August 27, 2020, 03:48:04 pm »
Here is my entry, cool off with this :)

Code: QB64: [Select]
1. _TITLE "Particle Fountain" 'b+ 2020-08-27
2. CONST nP = 15000
3. TYPE particle
4.     dx AS SINGLE
5.     dy AS SINGLE
6. DIM SHARED p(1 TO nP) AS particle
7. SCREEN _NEWIMAGE(1200, 600, 32)
8. _DELAY .25
9. FOR i = 1 TO nP
10.     new i
11. COLOR , &HFF002200
12.     IF lp < nP THEN lp = lp + 1
13.     FOR i = 1 TO lp
14.         p(i).dy = p(i).dy + .1
15.         p(i).x = p(i).x + p(i).dx
16.         p(i).y = p(i).y + p(i).dy
17.         IF p(i).x < 0 OR p(i).x > _WIDTH THEN new i
18.         IF p(i).y > _HEIGHT AND p(i).dy > 0 THEN
19.             p(i).dy = -.75 * p(i).dy: p(i).y = _HEIGHT - 5
20.         CIRCLE (p(i).x, p(i).y), 1, p(i).c
21.     _LIMIT 60
22. SUB new (i)
23.     p(i).x = _WIDTH / 2 + RND * 20 - 10
24.     p(i).y = _HEIGHT + RND * 5
25.     p(i).dx = RND * 3 - 1.5
26.     p(i).dy = -10
27.     p(i).c = _RGB32(50 * RND + 165, 50 * RND + 165, 255)
28.

johnno56

• Forum Resident
• Posts: 1270
• Live long and prosper.
Re: Particle Fountain
« Reply #8 on: August 27, 2020, 07:21:21 pm »

Code: QB64: [Select]
1. _TITLE "Particle Fountain" 'b+ 2020-08-27
2. CONST nP = 15000
3. TYPE particle
4.     dx AS SINGLE
5.     dy AS SINGLE
6. DIM SHARED p(1 TO nP) AS particle
7. SCREEN _NEWIMAGE(1200, 600, 32)
8. _DELAY .25
9. FOR i = 1 TO nP
10.     new i
11. COLOR , &HFF002200
12.     IF lp < nP THEN lp = lp + 1
13.     FOR i = 1 TO lp
14.         p(i).dy = p(i).dy + .1
15.         p(i).x = p(i).x + p(i).dx
16.         p(i).y = p(i).y + p(i).dy
17.         IF p(i).x < 0 OR p(i).x > _WIDTH THEN new i
18.         IF p(i).y > _HEIGHT AND p(i).dy > 0 THEN
19.             tmp = (INT(RND * 8) + 1) / 10
20.             p(i).dy = p(i).dy * -0.3 - tmp
21.             p(i).y = _HEIGHT - 5
22.         CIRCLE (p(i).x, p(i).y), p(i).r, p(i).c
23.     _LIMIT 60
24. SUB new (i)
25.     p(i).x = _WIDTH / 2 + RND * 20 - 10
26.     p(i).y = _HEIGHT + RND * 5
27.     p(i).dx = RND * 3 - 1.5
28.     p(i).dy = -10
29.     p(i).r = RND * 2
30.     p(i).c = _RGB32(50 * RND + 165, 50 * RND + 165, 255)
31.
32.
Logic is the beginning of wisdom.

bplus

• Global Moderator
• Forum Resident
• Posts: 8053
• b = b + ...
Re: Particle Fountain
« Reply #9 on: August 27, 2020, 07:30:38 pm »
Tinker and fiddle around:
Code: QB64: [Select]
1. _TITLE "Particle Fountain" 'b+ 2020-08-27
2. CONST nP = 30000
3. TYPE particle
4.     dx AS SINGLE
5.     dy AS SINGLE
6. DIM SHARED p(1 TO nP) AS particle
7. SCREEN _NEWIMAGE(1200, 600, 32)
8. _DELAY .25
9. FOR i = 1 TO nP
10.     new i
11. COLOR , &HFF002200
12.     IF lp < nP THEN lp = lp + 10
13.     FOR i = 1 TO lp
14.         p(i).dy = p(i).dy + .1
15.         p(i).x = p(i).x + p(i).dx
16.         p(i).y = p(i).y + p(i).dy
17.         IF p(i).x < 0 OR p(i).x > _WIDTH THEN new i
18.         IF p(i).y > _HEIGHT AND p(i).dy > 0 THEN
19.             p(i).dy = -.75 * p(i).dy: p(i).y = _HEIGHT - 5
20.         CIRCLE (p(i).x, p(i).y), p(i).r, p(i).c
21.     _LIMIT 60
22. SUB new (i)
23.     p(i).x = _WIDTH / 2 + RND * 20 - 10
24.     p(i).y = _HEIGHT + RND * 5
25.     p(i).dx = RND * 1 - .5
26.     p(i).dy = -10
27.     p(i).r = RND * 3
28.     p(i).c = _RGB32(50 * RND + 165, 50 * RND + 165, 255)
29.
30.
« Last Edit: August 27, 2020, 07:33:49 pm by bplus »

bplus

• Global Moderator
• Forum Resident
• Posts: 8053
• b = b + ...
Re: Particle Fountain
« Reply #10 on: August 27, 2020, 07:38:52 pm »
This is kinda funny:
Code: QB64: [Select]
1. _TITLE "Particle Fountain" 'b+ 2020-08-27
2. CONST nP = 30000
3. TYPE particle
4.     dx AS SINGLE
5.     dy AS SINGLE
6. DIM SHARED p(1 TO nP) AS particle
7. SCREEN _NEWIMAGE(1200, 600, 32)
8. _DELAY .25
9. FOR i = 1 TO nP
10.     new i
11. COLOR , &HFF002200
12.     IF lp < nP THEN lp = lp + 100
13.     FOR i = 1 TO lp
14.         p(i).dy = p(i).dy + .1
15.         p(i).x = p(i).x + p(i).dx
16.         p(i).y = p(i).y + p(i).dy
17.         IF p(i).x < 0 OR p(i).x > _WIDTH THEN new i
18.         IF p(i).y > _HEIGHT AND p(i).dy > 0 THEN
19.             p(i).dy = -.75 * p(i).dy: p(i).y = _HEIGHT - 5
20.         CIRCLE (p(i).x, p(i).y), p(i).r, p(i).c
21.     _LIMIT 60
22. SUB new (i)
23.     p(i).x = _WIDTH / 2 + RND * 20 - 10
24.     p(i).y = _HEIGHT + RND * 5
25.     p(i).dx = RND * 1 - .5
26.     p(i).dy = -10
27.     p(i).r = RND * 3
28.     p(i).c = _RGB32(50 * RND + 165, 50 * RND + 165, 255)
29.

SierraKen

• Forum Resident
• Posts: 1454
Re: Particle Fountain
« Reply #11 on: August 27, 2020, 08:16:38 pm »
WOW Bplus and Johno! Amazing stuff. Bplus, your last one is a masterpiece.

Dav

• Forum Resident
• Posts: 792
Re: Particle Fountain
« Reply #12 on: August 27, 2020, 10:03:58 pm »
Some pretty cool stuff posted here!  I sure like the water fountain effect, and in such a small amount of code too.

- Dav

Unseen Machine

• Forum Regular
• Posts: 158
• Make the game not the engine!
Re: Particle Fountain
« Reply #13 on: August 28, 2020, 05:35:24 am »
Wow, they are all goo but the last one by bplus is awesome, nice work guys.

Unseen

FellippeHeitor

• Guest
Re: Particle Fountain
« Reply #14 on: August 29, 2020, 01:57:17 pm »
What a bunch of show-offs!

Just kidding... great job you guys! Love the particle show.