Author Topic: Particles - just for fun  (Read 455 times)

FellippeHeitor

• QB64 Developer
• LET IT = BE
Particles - just for fun
« on: June 05, 2018, 05:08:11 PM »
Click to create an electromagnetic repeller field.

Code: [Select]
`SCREEN _NEWIMAGE(600, 600, 32)_DELAY .1_TITLE "Particles"TYPE PARTICLE    x AS SINGLE    xs AS SINGLE    y AS SINGLE    ys AS SINGLE    w AS SINGLE    h AS SINGLE    a AS SINGLE    r AS SINGLE    c AS _UNSIGNED LONGEND TYPEDIM particle(100) AS PARTICLEDIM SHARED r AS SINGLERANDOMIZE TIMERcreateParticles particle()DO    LINE (0, 0)-(_WIDTH, _HEIGHT), _RGBA32(0, 0, 0, 50), BF    updateAndShowParticles particle()    IF _MOUSEBUTTON(1) THEN        IF r < 150 THEN r = r + 1 ELSE r = 0        CIRCLE (_MOUSEX, _MOUSEY), r, _RGBA32(255, 255, 0, 150 - r)    END IF    _DISPLAY    _LIMIT 30LOOPSUB createParticles (this() AS PARTICLE)    FOR i = 0 TO UBOUND(this)        this(i).x = RND * _WIDTH        this(i).xs = 2 + RND * 3        this(i).y = RND * _HEIGHT        this(i).ys = 2 + RND * 3        this(i).w = RND * (_WIDTH / 4)        this(i).h = RND * (_WIDTH / 6)        this(i).a = RND * _PI(2)        this(i).r = RND * 3 + 1        this(i).c = _RGBA32(RND * 255, RND * 255, RND * 255, RND * 150 + 155)    NEXTEND SUBSUB updateAndShowParticles (this() AS PARTICLE)    WHILE _MOUSEINPUT: WEND    FOR i = 0 TO UBOUND(this)        this(i).a = this(i).a + .1        IF this(i).a > _PI(2) THEN this(i).a = this(i).a - _PI(2)        IF _MOUSEBUTTON(1) THEN            IF this(i).y > _MOUSEY THEN this(i).y = this(i).y + r / 15            IF this(i).y < _MOUSEY THEN this(i).y = this(i).y - r / 15            IF this(i).x > _MOUSEX THEN this(i).x = this(i).x + r / 15            IF this(i).x < _MOUSEX THEN this(i).x = this(i).x - r / 15        ELSE            r = 0            IF this(i).y > _MOUSEY THEN this(i).y = this(i).y - this(i).ys            IF this(i).y < _MOUSEY THEN this(i).y = this(i).y + this(i).ys            IF this(i).x > _MOUSEX THEN this(i).x = this(i).x - this(i).xs            IF this(i).x < _MOUSEX THEN this(i).x = this(i).x + this(i).xs        END IF        CircleFill this(i).x + COS(this(i).a) * this(i).w, this(i).y + SIN(this(i).a) * this(i).h, this(i).r, this(i).c    NEXTEND SUBSUB CircleFill (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)    x0 = R    y0 = 0    e = 0    DO WHILE y0 < x0        IF e <= 0 THEN            y0 = y0 + 1            LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF            LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF            e = e + 2 * y0        ELSE            LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF            LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF            x0 = x0 - 1            e = e - 2 * x0        END IF    LOOP    LINE (x - R, y)-(x + R, y), C, BFEND SUB`
« Last Edit: June 05, 2018, 05:12:50 PM by FellippeHeitor »

bplus

Re: Particles - just for fun
« Reply #1 on: June 05, 2018, 05:41:44 PM »
That's cool how they form orbits around mouse position. :)
B = B + ...

johnno56

• Live long and prosper.
Re: Particles - just for fun
« Reply #2 on: June 05, 2018, 10:14:01 PM »
Cool... Reminds me of blowflies following a dunny (sewage) truck... Not the programming... The movement of the particles... Stone the flammin' crows! Dodged a bullet there...

J
Logic is the beginning of wisdom.

FellippeHeitor

• QB64 Developer
• LET IT = BE
Re: Particles - just for fun
« Reply #3 on: June 05, 2018, 11:31:33 PM »
Well, I gotta admit: my first naming choice for my variables was DIM fly(100) AS FLY, but then I decided to go with the more generic 'particle()', but I'm guilty as charged. They have been flies all along.

Ashish

• The joy of coding is endless.
Re: Particles - just for fun
« Reply #4 on: June 06, 2018, 10:28:44 AM »
Nice effect!
if (Me.success) {Me.improve()} else {Me.tryAgain()}

My Projects - https://github.com/AshishKingdom?tab=repositories

FellippeHeitor

• QB64 Developer
• LET IT = BE
Re: Particles - just for fun
« Reply #5 on: June 06, 2018, 04:12:06 PM »
Flies all over.
« Last Edit: June 06, 2018, 04:13:46 PM by FellippeHeitor »

bplus

Re: Particles - just for fun
« Reply #6 on: June 06, 2018, 07:59:06 PM »
Inspiring! :-))
B = B + ...

KingRat

Re: Particles - just for fun
« Reply #7 on: June 18, 2018, 05:36:46 AM »
I like these kind of effects... good job!

I saw the guy who programmed "Black Annex" doing something like this on youtube.