Here’s another useless program. I call it constellations because at the start it reminds me of constellations on a star chart. When the program starts, I draw 400 random dots and then draw a line from each dot to its closest neighbor. Tap the screen and I increment the line count and connect each dot with its closest 2 neighbors. Keep tapping the screen and I increment the line count. I display the count in the upper left corner. Tap at the top of the screen to redraw another 400 random dots and connect with 1 line. As I said, it’s a useless program but kind of interesting.
displayMode(FULLSCREEN)
function setup()
nbr=1
lin,tab={},{}
dots()
lines()
end
function draw()
background(0)
stroke(255, 238, 0, 255)
strokeWidth(1)
for a,b in pairs(lin) do
line(b.x,b.y,b.z,b.w)
end
noStroke()
fill(255, 0, 0, 255)
for a,b in pairs(tab) do
ellipse(b.x,b.y,8)
end
fill(255)
text(nbr,10,HEIGHT-20)
end
function dots()
nbr=1
tab={}
for z=1,400 do
table.insert(tab,vec2(math.random(WIDTH),math.random(HEIGHT)))
end
lines()
end
function lines()
lin={}
for a,b in pairs(tab) do
v1=b
dTab={}
for z=1,nbr do
table.insert(dTab,vec3(0,0,9999))
end
for c,d in pairs(tab) do
dst=v1:dist(d)
p=vec3(d.x,d.y,dst)
if dst>0 then
for z=1,#dTab do
if p.z<dTab[z].z then
t=dTab[z]
dTab[z]=p
p=t
end
end
end
end
for r,s in pairs(dTab) do
table.insert(lin,vec4(b.x,b.y,s.x,s.y))
end
end
end
function touched(t)
if t.state==BEGAN then
if t.y>HEIGHT-50 then
dots()
return
end
nbr=nbr+1
lines()
end
end