xxxxxxxxxx
147
DEBUGGING = 0
const startSeed = 0x2A; // of course lmao
const world = []
const RENDER_DIST = 3; // min 1, add 2 every time
var middle;
const W = 512;
const H = 512;
var maincanv
var X = 0;
var Y = 0;
var PX = 0;
var PY = 0;
function setup() {
angleMode(DEGREES); // note this
createCanvas(W, H);
background(255);
randomSeed(startSeed);
noiseSeed(startSeed);
middle = floor((RENDER_DIST*RENDER_DIST-1)/2)
print(`debug: middle index ${middle}`)
for (let y = 0; y < RENDER_DIST; y++){
for (let x= 0; x < RENDER_DIST; x++ )
{
var canv = createGraphics(W,H)
canv.background(noise(x, y)*255,255,255,100)
canv.textSize(40)
canv.text(`${x} ${y}`,45 , 45)
world.push([x*W - (RENDER_DIST/2)*W,
y*H - (RENDER_DIST/2)*H,
canv
])
}
}
swapmaincanvas()
}
var t = 0;
var dt = 0.005;
function search(octree, xmin, ymin, zmin, xmax, ymax, zmax) {
// taken directly from https://github.com/vasturiano/d3-octree
const results = [];
octree.visit(function(node, x1, y1, z1, x2, y2, z2) {
if (!node.length) {
do {
const d = node.data;
if (d[0] >= xmin && d[0] < xmax && d[1] >= ymin && d[1] < ymax && d[2] >= zmin && d[2] < zmax) {
results.push(d);
}
} while (node = node.next);
}
return x1 >= xmax || y1 >= ymax || z1 >= zmax || x2 < xmin || y2 < ymin || z2 < zmin;
});
return results;
}
function swapmaincanvas(){
maincanv = world[middle][2]
maincanv.strokeWeight(15)
maincanv.translate(W/2,H/2)
}
function checkCanvases() {
// stepped right
if (X > W/2) {
print('now')
// world[middle + 1][2].image(maincanv,0,0)
maincanv = world[middle][2]
maincanv.rect(15,15,50)
// swapmaincanvas()
}
// // stepped left
// if (X % W == -1 && PX % W == 0) {
// world[middle - 1][2].image(maincanv,0,0)
// maincanv = world[middle - 1]
// swapmaincanvas()
// }
// // stepped down
// if (Y % H == 1 && PY % H == 0) {
// world[middle - RENDER_DIST][2].image(maincanv,0,0)
// maincanv = world[middle - RENDER_DIST]
// swapmaincanvas()
// }
// // stepped up
// if (Y % H == -1 && PY % H == 0) {
// world[middle + RENDER_DIST][2].image(maincanv,0,0)
// maincanv = world[middle + RENDER_DIST]
// swapmaincanvas()
// }
}
function draw() {
background(255)
if (/*w*/ keyIsDown(87)) {PY =Y; Y -=1;}
if (/*a*/ keyIsDown(65)) {PX =X; X -=1;}
if (/*s*/ keyIsDown(83)) {PY =Y; Y +=1;}
if (/*d*/ keyIsDown(68)) {PX =X; X +=1;}
checkCanvases()
translate(W/2,H/2)
scale(0.3)
maincanv.point((X%W),(Y%H));
for (const [cx,cy,canv] of world) {
image(canv, cx-X, cy-Y)
}
}