## Chaotic Scatter

Charlie Veniot11th August 2022 at 8:42pm
``````' based on a QBJS program by Vince
' http://basic4all.epizy.com/index.php?topic=206.msg2187#new

Dim  as double sw, sh, r, rr0, sx, sy, mw, mx, my, mb, rr, valid, old_mx, old_my, old_mw

sw = 1280
sh = 768

Dim pi As Double
pi = 4 * Atn(1)

Dim As Double t, a, b, a1, a2
Dim As Double x, y, x0, y0, x1, y1, dx, dy

r = 210
rr0 = 140

sx = 0
sy = sh / 2
Screen _NewImage(sw, sh, 14)
_sndwave "square"

waitfornomousebutton:
getmouse nmx, nmy, nmw2, nmb
if nmb = 1 THEN goto waitfornomousebutton

Do

'Do While _MouseInput
'mw = mw + _MouseWheel
'Loop

'If _KeyDown(87) or _KeyDown(119) then 'W
'    mw = mw - 1
'ElseIf _KeyDown(83) or _KeyDown(115) then 'S
'    mw = mw + 1
'End If

this_inkey\$ = ucase\$(inkey\$)
If this_inkey\$ = "W" then 'W
mw = mw - 1
ElseIf this_inkey\$ = "S" then 'S
mw = mw + 1
End If

' mx = _MouseX
' my = _MouseY
' mb = _MouseButton(1)
getmouse mx, my, mw2, mb

rr = rr0 - mw

If mb Then
Do While mb
'Do While _MouseInput
'Loop
'mb = _MouseButton(1)
getmouse mx, my, mw, mb
Loop

valid = -1
For b = 0 To 2 * pi Step 2 * pi / 3
x1 = r * Cos(b) + sw / 2
y1 = r * Sin(b) + sh / 2

dx = mx - x1
dy = my - y1
If dx * dx + dy * dy < rr * rr Then
valid = 0
goto exitforB
End If
Next
exitforB:

If valid Then
sx = mx
sy = my
End If
End If

'if mx<>old_mx or my<>old_my or mw<>old_mw then
If 1 Then

'line (0,0)-(sw,sh), _rgb(0,0,0), bf
'Line (0, 0)-(sw, sh), _RGBA32(0, 0, 0, 30), BF
Line (0, 0)-(sw, sh), &h000000, BF

'locate 1,1
'? mx, my, mw, mb

For b = 0 To 2 * pi Step 2 * pi / 3
Circle (r * Cos(b) + sw / 2, r * Sin(b) + sh / 2), rr, &hffffff
Circle (r * Cos(b) + sw / 2, r * Sin(b) + sh / 2), rr-1, &hffffff
Next

a = _Atan2(my - sy, mx - sx)

x0 = sx
y0 = sy

For t = 0 To 1000
x = t * Cos(a) + x0
y = t * Sin(a) + y0

For b = 0 To 2 * pi Step 2 * pi / 3
If x >= 0 And x < sw And y >= 0 And y < sh Then
x1 = r * Cos(b) + sw / 2
y1 = r * Sin(b) + sh / 2

dx = x - x1
dy = y - y1
If dx * dx + dy * dy < rr * rr Then
a1 = _Atan2(dy, dx)
a2 = 2 * a1 - a - pi

'Line (x0, y0)-(x, y), _RGB(233, 205, 89)
Line (x0, y0)-(x, y), &hdfcd59
sound 13, 0.00125
x0 = x
y0 = y
a = a2
t = 0
goto exitforA
End If
End If
Next
exitforA:
Next

'Line (x0, y0)-(x, y), _RGB(233, 205, 89)
Line (x0, y0)-(x, y), &hdfcd59

End If

old_mx = mx
old_my = my
old_mw = mw

'_Display
'_Limit 50
_delay 1/50
Loop Until _KeyHit = 27
``````