'https://retrobasic.allbasic.info/index.php?topic=721.0
'converting to JB. Tsh73 Feb 2022
'converting to QB64 b+ 2022-03-02 and Mods >>>> moving balls, move your mouse!
Const scrw
= 320, scrh
= 200
qb(0) = &HFF000000
qb(1) = &HFF000088
qb(2) = &HFF008800
qb(3) = &HFF008888
qb(4) = &HFF880000
qb(5) = &HFF880088
qb(6) = &HFF888800
qb(7) = &HFFCCCCCC
qb(8) = &HFF888888
qb(9) = &HFF0000FF
qb(10) = &HFF00FF00
qb(11) = &HFF00FFFF
qb(12) = &HFFFF0000
qb(13) = &HFFFF00FF
qb(14) = &HFFFFFF00
qb(15) = &HFFFFFFFF
' pal 16,255,255,255:
pal(16) = &HFFFFFFFF
' pal 32,0,192,255:
pal(32) = &HFF00CCFF
' pal 255,0,0,192:
pal(255) = &HFF0000CC
' rainbow 16 to 32:
rainbow 16, 32
' rainbow 32 to 255
rainbow 32, 255
Dim c
(spheres
, 3), r
(spheres
), q
(spheres
), cl
(4), d
(spheres
, 3) w = scrw / 2: h = scrh / 2: s = 0
cl(1) = 6: cl(2) = 1
cl(3) = cl(1) + 8: cl(4) = cl(2) + 8
c(k, 1) = c1: c(k, 2) = c2: c(k, 3) = c3
d
(k
, 1) = .01 * (Rnd - .5): d
(k
, 2) = .01 * (Rnd - .5): d
(k
, 3) = .01 * (Rnd - .5) r(k) = r: q(k) = r * r
lc = lc + 1
If lc
= 50 Then toggle
= 1 - toggle: lc
= 0 c(k, 1) = c(k, 1) + d(k, 1): c(k, 2) = c(k, 2) + d(k, 2): c(k, 3) = c(k, 3) + d(k, 3)
c(k, 1) = c(k, 1) - d(k, 1): c(k, 2) = c(k, 2) - d(k, 2): c(k, 3) = c(k, 3) - d(k, 3)
x = 0.3: y = -0.5: z = 0: ba = 3
dx = j - w: dy = h - i: dz = (scrh / 480) * 600
dd = dx * dx + dy * dy + dz * dz
recurs:
b1 = (y >= 0): b2 = (dy <= 0)
n = n - b3
n
= 0 - -(y
>= 0 Or dy
<= 0)
px = c(k, 1) - x: py = c(k, 2) - y: pz = c(k, 3) - z
pp = px * px + py * py + pz * pz
sc = px * dx + py * dy + pz * dz
bb = sc * sc / dd
aa = q(k) - pp + bb
continueK:
'plot ink 16+(dy*dy/dd)*240;j,scrh-i
c
= Int(16 + (dy
* dy
/ dd
) * 240) '#gr "color ";c;" ";c;" ";c
If lastCol
<> c
Then 'prevent extra color switching - JB speed-up lastCol = c
dx = dx * s: dy = dy * s: dz = dz * s: dd = dd * s * s
x = x + dx: y = y + dy: z = z + dz
nx = x - c(n, 1): ny = y - c(n, 2): nz = z - c(n, 3)
nn = nx * nx + ny * ny + nz * nz
l = 2 * (dx * nx + dy * ny + dz * nz) / nn
dx = dx - nx * l: dy = dy - ny * l: dz = dz - nz * l
GoTo recurs
'really only GOTO u = c(k, 1) - x
v = c(k, 3) - z
ba = 1
'needs "int to lower" vs "int to 0"
'If (x - (Int(x) - (x <> Int(x)) * (x < 0)) > .5) = (z - (Int(z) - (z <> Int(z)) * (z < 0)) > .5) Then
'If (x Mod 1 + (x < 0) > .5) = (z Mod 1 + (z < 0) > .5) Then
ik = cl(ba)
ik = cl(ba + 1)
'plot ink ik;j,scrh-i
'#gr "color ";ik;" ";ik;" ";ik
If lastCol
<> ik
Then 'prevent extra color switching lastCol = ik
continueJ:
Sub rainbow
(startIdx
, stopIdx
) For i
= startIdx
+ 1 To stopIdx
- 1 a = 1 - (stopIdx - i) / (stopIdx - startIdx) 'startIdx..stopIdx -> 0..1
R
= Int(r0
* (1 - a
) + r1
* a
) G
= Int(g0
* (1 - a
) + g1
* a
) B
= Int(b0
* (1 - a
) + b1
* a
)