Author Topic: Something with particles  (Read 6604 times)

0 Members and 1 Guest are viewing this topic.

FellippeHeitor

  • Guest
Something with particles
« on: August 02, 2018, 02:33:03 pm »
Here's something with particles.

Code: QB64: [Select]
  1. TYPE VERTEX
  2.     x AS SINGLE
  3.     y AS SINGLE
  4.     xv AS SINGLE
  5.     xa AS SINGLE
  6.     yv AS SINGLE
  7.     ya AS SINGLE
  8.     life AS SINGLE
  9.     stepToTake AS INTEGER
  10.  
  11. DIM particle(1000) AS VERTEX, m AS INTEGER
  12. DIM SHARED click AS VERTEX
  13.  
  14. SCREEN _NEWIMAGE(800, 600, 32)
  15.  
  16.  
  17.         click.x = _MOUSEX
  18.         click.y = _MOUSEY
  19.     END IF
  20.  
  21.     CLS
  22.     show particle()
  23.     _DISPLAY
  24.     _LIMIT 60
  25.  
  26. SUB show (particles() AS VERTEX)
  27.     DIM i AS LONG, this AS VERTEX
  28.     DIM r AS SINGLE
  29.  
  30.     FOR i = 1 TO UBOUND(particles)
  31.         this = particles(i)
  32.         CircleFill this.x, this.y, map(this.life, 0, 255, 1, 2), _RGB32(255, this.life)
  33.         this.life = this.life + this.stepToTake
  34.  
  35.         this.xv = this.xv + this.xa
  36.         this.yv = this.yv + this.ya
  37.         this.x = this.x + this.xv
  38.         this.y = this.y + this.yv
  39.  
  40.         IF this.life > 255 THEN
  41.             this.stepToTake = this.stepToTake * -1
  42.         ELSEIF this.life <= 0 THEN
  43.             this.x = RND * _WIDTH
  44.             this.y = RND * _HEIGHT
  45.             this.xv = 0
  46.             this.yv = 0
  47.             this.xa = 0
  48.             this.ya = 0
  49.             this.stepToTake = RND * 3
  50.         END IF
  51.  
  52.         CIRCLE (_MOUSEX, _MOUSEY), 30, _RGB32(255, 139, 0)
  53.  
  54.         IF click.x > 0 AND click.y > 0 AND dist(click.x, click.y, this.x, this.y) < 15 THEN
  55.             r = RND * 5
  56.             this.xa = COS(r)
  57.             this.ya = SIN(r)
  58.         END IF
  59.         particles(i) = this
  60.     NEXT
  61.  
  62.     click.x = 0
  63.     click.y = 0
  64.  
  65. FUNCTION dist! (x1!, y1!, x2!, y2!)
  66.     dist! = _HYPOT((x2! - x1!), (y2! - y1!))
  67.  
  68. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  69.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  70.  
  71. SUB CircleFill (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
  72.     x0 = R
  73.     y0 = 0
  74.     e = 0
  75.     DO WHILE y0 < x0
  76.         IF e <= 0 THEN
  77.             y0 = y0 + 1
  78.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  79.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  80.             e = e + 2 * y0
  81.         ELSE
  82.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  83.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  84.             x0 = x0 - 1
  85.             e = e - 2 * x0
  86.         END IF
  87.     LOOP
  88.     LINE (x - R, y)-(x + R, y), C, BF
  89.  

@v: if I make e = -R, small circles become squares.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Something with particles
« Reply #1 on: August 02, 2018, 07:20:42 pm »
  • Best Answer
  • Line #40 CircleFill this.x, this.y, map(this.life, 0, 255, 1, 2), _RGB32(255, this.life) is missing the third colour parameter... Threw in a zero just to get it running.... Very cool effect. Are you going to give it a name?

    J
    Logic is the beginning of wisdom.

    Offline bplus

    • Global Moderator
    • Forum Resident
    • Posts: 8053
    • b = b + ...
      • View Profile
    Re: Something with particles
    « Reply #2 on: August 02, 2018, 07:35:08 pm »
  • Best Answer
  • Hi Johnno

    _RGB32 has been updated to handle more options see reply#8 here:
    https://www.qb64.org/forum/index.php?topic=304.msg2558#msg2558

    in the case above it is same as _rgba32(255, 255, 255,(and alpha setting) this.life)
    « Last Edit: August 02, 2018, 07:38:08 pm by bplus »

    Offline johnno56

    • Forum Resident
    • Posts: 1270
    • Live long and prosper.
      • View Profile
    Re: Something with particles
    « Reply #3 on: August 02, 2018, 07:47:15 pm »
  • Best Answer
  • I only put in the zero because the program died because of the wrong number of parameters...
    Logic is the beginning of wisdom.

    FellippeHeitor

    • Guest
    Re: Something with particles
    « Reply #4 on: August 02, 2018, 08:00:19 pm »
  • Best Answer
  • My bad. I forgot to mention I used the latest development build.

    Instead of adding in a 0, do as bplus indicated:_RGBA32(255, 255, 255, this.life)
    « Last Edit: August 02, 2018, 08:11:41 pm by FellippeHeitor »

    FellippeHeitor

    • Guest
    Re: Something with particles
    « Reply #5 on: August 02, 2018, 08:05:19 pm »
  • Best Answer
  • Very cool effect. Are you going to give it a name?

    J

    I wish I could remember what I started writing this for... Then naming it would be easier.

    Did you guys click around?

    Offline johnno56

    • Forum Resident
    • Posts: 1270
    • Live long and prosper.
      • View Profile
    Re: Something with particles
    « Reply #6 on: August 02, 2018, 09:30:09 pm »
  • Best Answer
  • As a rule I do not use development builds. The times that I had, in the majority of cases, they ran fine... I prefer 'fine'. But thank you for pointing the version you are using. Thought I was going nuts... well... more than usual anyway... lol

    Clicking around? Pfft... When I see, what looks like ANY kind of 'sight' on the screen, my trigger finger kicks into 'auto gunner' and the rest is as they say, history.... Bwahahaha....
    Logic is the beginning of wisdom.

    Offline bplus

    • Global Moderator
    • Forum Resident
    • Posts: 8053
    • b = b + ...
      • View Profile
    Re: Something with particles
    « Reply #7 on: August 02, 2018, 10:08:29 pm »
  • Best Answer
  • Very cool effect. Are you going to give it a name?

    J

    I wish I could remember what I started writing this for... Then naming it would be easier.

    Did you guys click around?

    Yes, I clicked around, I held my mouse button down and swirled it around, and it reminded me of the futility of dusting.

    FellippeHeitor

    • Guest
    Re: Something with particles
    « Reply #8 on: August 02, 2018, 10:13:11 pm »
  • Best Answer
  • That's a good name! The Futility of Star Dusting maybe.

    FellippeHeitor

    • Guest
    Re: Something with particles
    « Reply #9 on: August 02, 2018, 10:16:38 pm »
  • Best Answer
  • As a rule I do not use development builds. The times that I had, in the majority of cases, they ran fine... I prefer 'fine'. But thank you for pointing the version you are using. Thought I was going nuts... well... more than usual anyway... lol

    Since qb64 isn't "installed" but rather "unpacked", should you wanna give it a try and help beta test it it'd be a matter of, again, unpacking to a new folder. But to each their own.

    Clicking around? Pfft... When I see, what looks like ANY kind of 'sight' on the screen, my trigger finger kicks into 'auto gunner' and the rest is as they say, history.... Bwahahaha....


    Offline johnno56

    • Forum Resident
    • Posts: 1270
    • Live long and prosper.
      • View Profile
    Re: Something with particles
    « Reply #10 on: August 03, 2018, 12:54:43 am »
  • Best Answer
  • "as a rule" was used deliberately. But, after all, aren't rules meant to be bent, broken or destroyed?

    "Unpacked" into its own directory. Loaded the 'particles' program and it ran as it should. No errors. Cool.
    Logic is the beginning of wisdom.