_TITLE "Networking 1 translation" 'by B+ started 2018-11-13
' networking.bas SmallBASIC 0.12.9 [B+=MGA] 2017-04-14
' 2017-04-16 modified for new array method for drawpoly
' plus needed to check another distance!!!
'2018-11-12 add star background and alpha coloring
CONST xmax = 800
CONST ymax = 600
CONST nP = 85
CONST rD = 100
SCREEN _NEWIMAGE(xmax, ymax, 32)
_SCREENMOVE 80, 20
TYPE point
x AS SINGLE
y AS SINGLE
dx AS SINGLE
dy AS SINGLE
c AS _UNSIGNED LONG
END TYPE
DIM p(nP) AS point
'initialize points
FOR i = 0 TO nP
p(i).x = rand(0, xmax)
p(i).y = rand(0, ymax)
p(i).dx = rdir * (RND * 3 + .5)
p(i).dy = rdir * (RND * 2 + .5)
p(i).c = _RGBA32(rand(64, 255), rand(64, 255), rand(64, 255), 40)
NEXT
stars& = _LOADIMAGE("stars.png")
WHILE 1
'if inkey = " " then cls
_SOURCE stars&
_DEST 0
_PUTIMAGE
FOR i = 0 TO nP 'big show of points and triangle
COLOR p(i).c
LINE (p(i).x, p(i).y)-STEP(2, 2), p(i).c, BF
FOR j = i + 1 TO nP 'search for triangle points within 100 pixels
IF distance(p(i).x, p(i).y, p(j).x, p(j).y) < rD THEN
FOR k = j + 1 TO nP
IF distance(p(k).x, p(k).y, p(j).x, p(j).y) < rD THEN
IF distance(p(k).x, p(k).y, p(i).x, p(i).y) < rD THEN
'draw 3 lines of triangle
LINE (p(i).x, p(i).y)-(p(j).x, p(j).y), p(i).c
LINE (p(k).x, p(k).y)-(p(j).x, p(j).y), p(i).c
LINE (p(i).x, p(i).y)-(p(k).x, p(k).y), p(i).c
END IF
END IF
NEXT
END IF
NEXT
'update points
p(i).x = p(i).x + p(i).dx
p(i).y = p(i).y + p(i).dy
IF p(i).x < 0 THEN p(i).x = xmax + p(i).x
IF p(i).x > xmax THEN p(i).x = p(i).x - xmax
IF p(i).y < 0 THEN p(i).y = 0: p(i).dy = p(i).dy * -1
IF p(i).y > ymax THEN p(i).y = ymax: p(i).dy = p(i).dy * -1
NEXT
_DISPLAY
_LIMIT 30
WEND
FUNCTION rand& (lo, hi)
rand& = (RND * (hi - lo + 1)) \ 1 + lo
END FUNCTION
FUNCTION rdir%
IF RND < .5 THEN rdir% = -1 ELSE rdir% = 1
END FUNCTION
FUNCTION distance (x1, y1, x2, y2)
distance = ((x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5
END FUNCTION
Thanks to Johnno for the image used for background.