going to write a second part that turns the box table into an actual map grid array and make it a function…
function setup()
parameter("zoom",1,15,8)
parameter("boxes",20,500)
parameter("slowdown",1,9,4.5)
iparameter("clear",0,1)
iparameter("seed",1,99999,math.random(1,99999))
rectMode(CENTER)
touchmap = {}
rooms = {}
noSmooth()
table.insert(rooms,{vec2(0,0),vec2(3,3)})
math.randomseed(seed)
end
function touchsetup()
touchmap = {}
end
function touched(touch)
if touch.state == ENDED then
touchrelease(touch)
touchmap[touch.id] = nil
else
if touchmap[touch.id] == nil then touchstart(touch) end
touchmap[touch.id] = touch
end
end
function touchrelease(touch)
end
function touchstart(touch)
end
function draw()
translate(WIDTH/2,HEIGHT/2)
if clear == 1 then rooms = {{vec2(0,0),vec2(3,3)}}
math.randomseed(seed)
end
scale(zoom)
background(0, 0, 0, 255)
strokeWidth(0)
for i = 1,#rooms do
local me = rooms[i]
fill(255, 0, 0, 255)
if me[2].x == 1 then fill(255, 209, 0, 255) end
if me[2].x == 2 then fill(88, 105, 107, 255) end
rect(me[1].x,me[1].y,math.min(2.5,me[2].x),math.min(2.5,me[2].y))
end
local sanitylimit = 0
while #rooms < boxes do
sanitylimit = sanitylimit + 1
rooms = addroom(rooms)
if sanitylimit > 1000/(slowdown^3) then break end
end
end
function addroom(index)
table.sort(index,function(a,b) if a[2].x > b[2].x then return true end end)
local derp = 0
local hits = 0
local dir = {vec2(0,4),vec2(4,0),vec2(0,-4),vec2(-4,0)}
local num = math.min(math.ceil((math.random(1,#index+2))),#index)
local mov = dir[math.random(1,4)]
local spot = index[num][1] + mov
local spotb = index[num][1]
derp = 1
hits = 0
if index[num][2].y == 3 and spot.x/4 == math.ceil(spot.x/4) and spot.y/4 == math.ceil(spot.y/4) then
for i = 1,#index do
if index[i][1] == spot then derp = 0
if index[i][2].x == 3 then
hits = hits + 1 end
end
end
if derp == 1 then
if math.random(1,4) == 1 then
table.insert(index,{spot,vec2(2,2)})
else
table.insert(index,{spot,vec2(3,3)})
if math.random(1,4) <= 2 then
table.insert(index,{(spotb+spot)/2,vec2(2.5,2.5)}) else
table.insert(index,{(spotb+spot)/2,vec2(1,1)}) end
end
local spotbuff = spot
end end
if hits == 1 and math.random(1,22) == 1 then
local derpo = 0
for i = 1,#index do
if index[i][1] == (spotb+spot)/2 then
if math.random(0,3) == 1 then
derpo = 1
index[i][2] = vec2(2.5,2.5)
else
derpo = 1
end
end
end
if derpo == 0 then table.insert(index,{(spotb+spot)/2,vec2(2.5,2.5)}) end
end
return index
end