for(let i = 0; i < n + 2; i++){
for(let j = 0; j < n + 2; j++){
createCanvas(WIDTH, WIDTH);
sintime = sin(time)*0.2 + 1;
for(let i = 0; i <= n+1; i++){
for(let j = 0; j <= n+1; j++){
glob_points[i][j] = findPoint(i, j, w, h, sf, steps);
for(let i = 0; i <= n; i++){
for(let j = 0; j <= n; j++){
let off = 0.5*(1-SC)/SC * WIDTH
for(let i = 0; i < n; i++){
for(let j = 0; j < n; j++){
drawCell(i, j, w, h, sf, steps);
rect(0, 0, width, height)
function drawCell(i, j, w, h, sf, steps){
if(glob_points[i][j][3]){
let side1 = hor_lines[i][j];
let side2 = vert_lines[i+1][j];
let side3 = hor_lines[i][j+1];
let side4 = vert_lines[i][j];
let points = [].concat(side1[5], side2[5], side3[6], side4[6]);
for(let k = 1; k < points.length; k++){
let lastp = stack[stack.length-1];
if(newp[1] === lastp[1]){
line(newp[0][0], newp[0][1], lastp[0][0], lastp[0][1]);
function getSide(p1, p2){
return [[p1[0], p1[1]], [p2[0], p2[1]], p1[2], p2[2], Math.abs(p1[2]-p2[2]), []];
let p1 = glob_points[i][j];
let p2 = glob_points[i+1][j];
let side = getSide(p1, p2);
let p1 = glob_points[i][j];
let p2 = glob_points[i][j+1];
let side = getSide(p1, p2);
function getPoints(side){
for(let i=0; i < side[4]; i++){
let t = 1-(i+1)/(side[4]+1);
side[5].push([[side[0][0]*t + negt*side[1][0],
side[0][1]*t + negt*side[1][1]],
for(let i = 1; i <= side[5].length; i++){
let p = side[5][side[5].length - i];
side[6][i-1] = [p[0], (p[1]+1)%2];
function findPoint(i, j, w, h, sf, steps){
nois = floor(noise(x1*sf, sintime*Math.cos(time + y1*sf*HALF_PI)+100, sintime*Math.sin(time+ y1*sf*HALF_PI)+100) * (steps));
return([x1, y1, nois, false]);
function updateSides(i, j, go){
n1 = glob_points[i][j][2];
n2 = glob_points[i+1][j][2];
n3 = glob_points[i+1][j+1][2];
n4 = glob_points[i][j+1][2];
if( (n1 == n2) && (n2 == n3) && (n3 == n4) && (n4 == n1)){
glob_points[i][j][3] = true;
glob_points[i][j][3] = false;
vert_lines[i][j] = getVert(i, j);
hor_lines[i][j] = getHor(i, j);
if(n1 != vert_lines[i][j][2] || n4 != vert_lines[i][j][3]){
vert_lines[i][j] = getVert(i, j);
if(n1 != hor_lines[i][j][2] || n2 != hor_lines[i][j][3]){
hor_lines[i][j] = getHor(i, j);