And now with tinted triangles:
' ttri networking.bas SmallBASIC 0.12.9 [B+=MGA] 2017-04-16
' triangle fill.bas SmallBASIC 0.12.2 [B+=MGA] 2016-05-28
def rand(lo, hi) = (rnd * (hi - lo + 1)) \ 1 + lo
def rdir = iff(rnd < .5, -1, 1)
def distance(x1, y1, x2, y2) = ( (x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5
'Fast Filled Triangle Sub by AndyAmaya
sub ttri(x1, y1, x2, y2, x3, y3)
local x, y, sp, yy, length, slope1, slope2, slope3
'triangle coordinates must be ordered: where x1 < x2 < x3
if x2 < x1 then swap x1, x2 : swap y1, y2
if x3 < x1 then swap x1, x3 : swap y1, y3
if x3 < x2 then swap x2, x3 : swap y2, y3
if x1 <> x3 then slope1 = (y3 - y1) / (x3 - x1)
'draw the first half of the triangle
length = x2 - x1
if length <> 0 then
slope2 = (y2 - y1) / (x2 - x1)
for x = 0 to length step 3
if int(x * slope1 + y1) < int(x * slope2 + y1) then sp = 4 else sp = -4
for yy = int(x * slope1 + y1) to int(x * slope2 + y1) step sp
pset x + x1, yy
next
next
end if
'draw the second half of the triangle
y = length * slope1 + y1 : length = x3 - x2
if length <> 0 then
slope3 = (y3 - y2) / (x3 - x2)
for x = 0 To length step 3
if int(x * slope1 + y) < int(x * slope3 + y2) then sp = 4 else sp = -4
for yy = int(x * slope1 + y) to int(x * slope3 + y2) step sp
pset x + x2, yy
next
next
end if
end
nP = 85
dim p(nP)
for i = 0 to nP
p(i).x = rand(100, xmax-100)
p(i).y = rand(100, ymax-100)
p(i).dx = rdir * rnd * 6
p(i).dy = rdir * rnd * 3.5
p(i).c = rgb(rand(64, 255), rand(64, 255), rand(64, 255))
next
while 1
cls
for i = 0 to nP 'big show of points and triangle
color p(i).c
circle p(i).x, p(i).y, 2 filled
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) < 130 then
for k = j + 1 to NP
if distance(p(k).x, p(k).y, p(j).x, p(j).y) < 130 then
if distance(p(i).x, p(i).y, p(k).x, p(k).y) < 130 then
ttri p(i).x, p(i).y, p(j).x, p(j).y, p(k).x, p(k).y
fi
fi
next
fi
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 = 0 : p(i).dx = p(i).dx * -1
if p(i).x > xmax then p(i).x = xmax : p(i).dx = p(i).dx * -1
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
showpage
wend