09-18-2024, 10:37 PM
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
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