To compile you will need D3DFunc installed.
sync on
sync rate 0
cls
set display mode 1024,768,32
global max_points=2000
global point_amount=0
dim points#(max_points-1,1)
dim edges(max_points-1)
for i=0 to max_points-1
edges(i)=-1
next i
points#(0,0)=screen width()/2
points#(0,1)=screen height()/2
point_amount=1
d3d_init
do
cls
if point_amount<max_points-50 and spacekey()=0
x#=rnd(screen width())
y#=rnd(screen height())
min_d#=(points#(0,0)-x#)^2+(points#(0,1)-y#)^2
min_i=0
for i=1 to point_amount-1
d#=(points#(i,0)-x#)^2+(points#(i,1)-y#)^2
if d#<min_d#
min_i=i
min_d#=d#
endif
next i
min_d#=sqrt(min_d#)
l#=5+rnd(10)
if l#>min_d#
l#=min_d#
endif
nx#=(x#-points#(min_i,0))/min_d#
ny#=(y#-points#(min_i,1))/min_d#
x2#=points#(min_i,0)+l#*nx#
y2#=points#(min_i,1)+l#*ny#
points#(point_amount,0)=x2#
points#(point_amount,1)=y2#
edges(point_amount)=min_i
inc point_amount
endif
if mouseclick()=1
point_amount=1
points#(0,0)=mousex()
points#(0,1)=mousey()
for i=0 to max_points-1
edges(i)=-1
next i
endif
if mouseclick()=2 and lmouseclick=0
points#(point_amount,0)=mousex()
points#(point_amount,1)=mousey()
inc point_amount
endif
lmouseclick=mouseclick()
gosub draw_rrt
sync
loop
draw_rrt:
for i=0 to point_amount-1
d3d_dot points#(i,0),points#(i,1)
if edges(i)>-1
j=edges(i)
d3d_line points#(i,0),points#(i,1),points#(j,0),points#(j,1)
endif
next i
return