Author Topic: Particle Fountain  (Read 5901 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
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.             END IF
  31.             PSET (x, y), cc(amount)
  32.             skip:
  33.             mm = mm + 1
  34.             IF mm < 100 THEN GOTO skip2:
  35.             mm = 1
  36.             mmm = mmm + 1
  37.             IF mmm > 180 THEN mmm = 1
  38.             xx2 = (RND * 7) + 3
  39.             yy2 = (RND * 13) + 6
  40.             xx3 = (RND * 7) + 3
  41.             yy3 = (RND * 13) + 6
  42.  
  43.             x2 = x2 + xx2
  44.             y2 = y2 + yy2
  45.             x3 = x3 - xx3
  46.             y3 = y3 + yy3
  47.             IF y2 > 600 THEN y2 = 250: x2 = 700
  48.             IF y3 > 600 THEN y3 = 250: x3 = 500
  49.  
  50.             PSET (x2, y2), _RGB32(127, 255, 127)
  51.             PSET (x3, y3), _RGB32(127, 255, 127)
  52.  
  53.             xx4 = (RND * 30) - 30
  54.             yy4 = (RND * 40) - 40
  55.             xx5 = (RND * 30) - 30
  56.             yy5 = (RND * 40) - 40
  57.  
  58.             xx6 = (RND * 30) - 30
  59.             yy6 = (RND * 40) - 40
  60.             xx7 = (RND * 30) - 30
  61.             yy7 = (RND * 40) - 40
  62.  
  63.             PSET ((SIN(mmm) * 90) + 500 + xx4, (COS(mmm * 2) * -90) + 175 + yy4), _RGB32(127, 255, 127)
  64.             PSET ((SIN(mmm) * 90) + 700 + xx5, (COS(mmm * 2) * -90) + 175 + yy5), _RGB32(127, 255, 127)
  65.  
  66.             PSET ((SIN(mmm / 2) * 90) + 500 + xx6, (COS(mmm) * -90) + 250 + yy6), _RGB32(127, 255, 127)
  67.             PSET ((SIN(mmm / 2) * 90) + 700 + xx7, (COS(mmm) * -90) + 250 + yy7), _RGB32(127, 255, 127)
  68.  
  69.  
  70.             skip2:
  71.         NEXT t
  72.         tt = 2
  73.     NEXT amount
  74.     _DISPLAY
  75.     CLS
  76.     LINE (500, 250)-(700, 600), _RGB32(127, 255, 127), B
  77.     m = m + 1
  78.     IF m = 200 THEN m = 0: GOTO start:
  79.  

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
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.   CLS
  16.  
  17. REM $INCLUDE:'UnseenGDK.bm'

Unseen

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
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?

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
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!

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
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.   CLS
  13.  
  14.   FOR x% = 350 TO 450
  15.     GDK_Emitter_New Emitter, x%, 600, RND * (10) + 10, 0, 0, 2, 5, .5, 5
  16.     GDK_Particles_Spawn Emitter, Particle(), PMax&, _RGB32(RND * (255) + 150, 0, 0), _RGB(0, RND * (5) + 2, 0), 2
  17.   NEXT
  18.  
  19.   GDK_Particles_Draw Particle(), PMax&
  20.   GDK_Particles_Update Particle(), PMax&
  21.  
  22.  
  23.  
  24.  
  25.  
  26. REM $INCLUDE:'UnseenGDK.bm'
* UnseenGDK.bm (Filesize: 42.03 KB, Downloads: 207)
« Last Edit: August 27, 2020, 01:26:29 pm by Unseen Machine »

Offline SierraKen

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

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
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. :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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.     x AS SINGLE
  5.     y AS SINGLE
  6.     dx AS SINGLE
  7.     dy AS SINGLE
  8.     c AS _UNSIGNED LONG
  9. DIM SHARED p(1 TO nP) AS particle
  10. SCREEN _NEWIMAGE(1200, 600, 32)
  11. _DELAY .25
  12. FOR i = 1 TO nP
  13.     new i
  14. COLOR , &HFF002200
  15.     CLS
  16.     IF lp < nP THEN lp = lp + 1
  17.     FOR i = 1 TO lp
  18.         p(i).dy = p(i).dy + .1
  19.         p(i).x = p(i).x + p(i).dx
  20.         p(i).y = p(i).y + p(i).dy
  21.         IF p(i).x < 0 OR p(i).x > _WIDTH THEN new i
  22.         IF p(i).y > _HEIGHT AND p(i).dy > 0 THEN
  23.             p(i).dy = -.75 * p(i).dy: p(i).y = _HEIGHT - 5
  24.         END IF
  25.         CIRCLE (p(i).x, p(i).y), 1, p(i).c
  26.     NEXT
  27.     _DISPLAY
  28.     _LIMIT 60
  29. SUB new (i)
  30.     p(i).x = _WIDTH / 2 + RND * 20 - 10
  31.     p(i).y = _HEIGHT + RND * 5
  32.     p(i).dx = RND * 3 - 1.5
  33.     p(i).dy = -10
  34.     p(i).c = _RGB32(50 * RND + 165, 50 * RND + 165, 255)
  35.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Particle Fountain
« Reply #8 on: August 27, 2020, 07:21:21 pm »
I just 'had' to tinker....

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

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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.     x AS SINGLE
  5.     y AS SINGLE
  6.     dx AS SINGLE
  7.     dy AS SINGLE
  8.     r AS SINGLE
  9.     c AS _UNSIGNED LONG
  10. DIM SHARED p(1 TO nP) AS particle
  11. SCREEN _NEWIMAGE(1200, 600, 32)
  12. _DELAY .25
  13. FOR i = 1 TO nP
  14.     new i
  15. COLOR , &HFF002200
  16.     CLS
  17.     IF lp < nP THEN lp = lp + 10
  18.     FOR i = 1 TO lp
  19.         p(i).dy = p(i).dy + .1
  20.         p(i).x = p(i).x + p(i).dx
  21.         p(i).y = p(i).y + p(i).dy
  22.         IF p(i).x < 0 OR p(i).x > _WIDTH THEN new i
  23.         IF p(i).y > _HEIGHT AND p(i).dy > 0 THEN
  24.             p(i).dy = -.75 * p(i).dy: p(i).y = _HEIGHT - 5
  25.         END IF
  26.         CIRCLE (p(i).x, p(i).y), p(i).r, p(i).c
  27.     NEXT
  28.     _DISPLAY
  29.     _LIMIT 60
  30. SUB new (i)
  31.     p(i).x = _WIDTH / 2 + RND * 20 - 10
  32.     p(i).y = _HEIGHT + RND * 5
  33.     p(i).dx = RND * 1 - .5
  34.     p(i).dy = -10
  35.     p(i).r = RND * 3
  36.     p(i).c = _RGB32(50 * RND + 165, 50 * RND + 165, 255)
  37.  
  38.  
« Last Edit: August 27, 2020, 07:33:49 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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.     x AS SINGLE
  5.     y AS SINGLE
  6.     dx AS SINGLE
  7.     dy AS SINGLE
  8.     r AS SINGLE
  9.     c AS _UNSIGNED LONG
  10. DIM SHARED p(1 TO nP) AS particle
  11. SCREEN _NEWIMAGE(1200, 600, 32)
  12. _DELAY .25
  13. FOR i = 1 TO nP
  14.     new i
  15. COLOR , &HFF002200
  16.     CLS
  17.     IF lp < nP THEN lp = lp + 100
  18.     FOR i = 1 TO lp
  19.         p(i).dy = p(i).dy + .1
  20.         p(i).x = p(i).x + p(i).dx
  21.         p(i).y = p(i).y + p(i).dy
  22.         IF p(i).x < 0 OR p(i).x > _WIDTH THEN new i
  23.         IF p(i).y > _HEIGHT AND p(i).dy > 0 THEN
  24.             p(i).dy = -.75 * p(i).dy: p(i).y = _HEIGHT - 5
  25.         END IF
  26.         CIRCLE (p(i).x, p(i).y), p(i).r, p(i).c
  27.     NEXT
  28.     _DISPLAY
  29.     _LIMIT 60
  30. SUB new (i)
  31.     p(i).x = _WIDTH / 2 + RND * 20 - 10
  32.     p(i).y = _HEIGHT + RND * 5
  33.     p(i).dx = RND * 1 - .5
  34.     p(i).dy = -10
  35.     p(i).r = RND * 3
  36.     p(i).c = _RGB32(50 * RND + 165, 50 * RND + 165, 255)
  37.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
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.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
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

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
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.