Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How about some vector noodles?
#20
That's neat too, bplus.  I was playing around with your mod some.  You know I've been messing with bouncing and velocity lately, so couldn't resist using it.  Here's a swarm.   Mouse still controls.

Really surprised so many particles can be handled smoothly. 

- Dav

Code: (Select All)
_Title "Dav's overhaul of bplus' overhaul Vector noodling of Terry Ritchie"

' Move mouse to attract particles
' Press left mouse button to repel particles


Const PARTICLES = 250000
Const SWIDTH = 960
Const SHEIGHT = 540

Type PARTICLE
    x As Single
    y As Single
    vx As Single
    vy As Single
End Type

Dim Particle(PARTICLES - 1) As PARTICLE
Dim p As Long
Dim dx As Single
Dim dy As Single
Dim Circ As Long

Circ = _NewImage(11, 11, 32)
_Dest Circ
Circle (5, 5), 5
Paint (5, 5)

Randomize Timer
Do
    Particle(p).x = Rnd * SWIDTH
    Particle(p).y = Rnd * SHEIGHT
    Particle(p).vx = Rnd * 2 - 1 'velocity
    Particle(p).vy = Rnd * 2 - 1
    p = p + 1
Loop Until p = PARTICLES

Screen _NewImage(SWIDTH, SHEIGHT, 32)
_ScreenMove 250, 70
_MouseHide
Color &HFF000000, &HFFFFFFFF
Do
    Cls
    _Limit 120
    p = 0
    Do
        PSet (Particle(p).x, Particle(p).y)
        While _MouseInput: Wend
        dx = _MouseX - Particle(p).x
        dy = _MouseY - Particle(p).y
        d = _Hypot(dx, dy)
        If d > 1 Then
            If _MouseButton(1) Then
                Particle(p).vx = Particle(p).vx - (dx / d) * .5 'scale down velocity (.5)
                Particle(p).vy = Particle(p).vy - (dy / d) * .5 '
            Else
                Particle(p).vx = Particle(p).vx + (dx / d) * .5
                Particle(p).vy = Particle(p).vy + (dy / d) * .5
            End If
        End If
        Particle(p).vx = Particle(p).vx * .99 'damper factor (.99)
        Particle(p).vy = Particle(p).vy * .99
        Particle(p).x = Particle(p).x + Particle(p).vx
        Particle(p).y = Particle(p).y + Particle(p).vy
        If Particle(p).x < 0 Or Particle(p).x >= SWIDTH Then Particle(p).vx = -Particle(p).vx
        If Particle(p).y < 0 Or Particle(p).y >= SHEIGHT Then Particle(p).vy = -Particle(p).vy
        p = p + 1
    Loop Until p = PARTICLES
    _PutImage (_MouseX - 5, _MouseY - 5), Circ
    _Display
Loop Until _KeyDown(27)
System

Find my programs here in Dav's QB64 Corner
Reply


Messages In This Thread
How about some vector noodles? - by TerryRitchie - 05-13-2024, 03:30 PM
RE: How about some vector noodles? - by bplus - 05-13-2024, 04:43 PM
RE: How about some vector noodles? - by Sprezzo - 05-13-2024, 05:42 PM
RE: How about some vector noodles? - by GareBear - 05-13-2024, 08:17 PM
RE: How about some vector noodles? - by bplus - 05-13-2024, 11:33 PM
RE: How about some vector noodles? - by NakedApe - 05-14-2024, 01:15 AM
RE: How about some vector noodles? - by Sprezzo - 05-14-2024, 04:11 PM
RE: How about some vector noodles? - by bplus - 05-14-2024, 04:26 PM
RE: How about some vector noodles? - by Sprezzo - 05-14-2024, 04:28 PM
RE: How about some vector noodles? - by bplus - 05-14-2024, 04:40 PM
RE: How about some vector noodles? - by Sprezzo - 05-14-2024, 06:44 PM
RE: How about some vector noodles? - by Dav - 09-17-2024, 11:06 AM
RE: How about some vector noodles? - by bplus - 09-17-2024, 03:01 PM
RE: How about some vector noodles? - by bplus - 09-18-2024, 08:07 PM
RE: How about some vector noodles? - by Dav - 09-18-2024, 10:37 PM
RE: How about some vector noodles? - by bplus - 09-18-2024, 10:51 PM
RE: How about some vector noodles? - by sbblank - 09-18-2024, 11:13 PM



Users browsing this thread: 6 Guest(s)