let qr;
let t, d, startGrid, endGrid;
let cells;
let nCells;
let bSize = 150;
let qrCodeGeometry;
function setup() {
let c = min(windowWidth, windowHeight) * 0.7;
angleMode(DEGREES)
lunarI = random(width/4,width*1.5)
col1 = [255, 255, 255, 255];
createCanvas(c, c, WEBGL);
nCells = 100
startGrid = 100
endGrid = 100
g = random(1,3)+nCells/100
h = random(2,10)+nCells/100
d = width/nCells;
qrCodeGeometry = buildGeometry(() => {
for (let i = 0; i < nCells ; i++) {
for (let j = 0; j < nCells ; j++) {
di = abs(dist(d * i,d*j,width/2,height/2))
if(di<width/2){
push();
if(abs(dist(d * i,d*j,lunarI,lunarI))>width/2){
rand1 = (width/2 -di)/(width/2)*
(i+bSize*abs(cos(i/g+j/(i+h) - i*j/(g*g))) - bSize/2*sin(i/h-j/g-di/(g+h))*cos(j*i*cos(g-i/h - di/500)/(g)));
}else{
rand1 = 0.3*(width/2 -di)/(width/2)*
(i+bSize*abs(cos(i/g+j/(i+h) - i*j/(g*g))) - bSize/2*sin(i/h-j/g-di/(g+h))*cos(j*i*cos(g-i/h - di/500)/(g)));
}
translate(-width / 2 + d * i, -height / 2 + d * j, rand1 / 2);
box(d, d, 10+rand1 );
pop();
}
}
}
});
}
function draw() {
t = frameCount / 10;
scale(0.6);
orbitControl();
rotateY((PI / 4) * sin(t / 2)+20);
rotateX((PI / 4) * sin(t / 5)+20);
rotateZ((PI / 4) * sin(t / 3)-20);
background(255);
pointLight(255, 255, 255, 600, 600, 600);
pointLight(255, 255, 255, -600, 600, 600);
specularMaterial(255);
model(qrCodeGeometry);
}
function keyPressed() {
if (keyCode === 83) {
qrCodeGeometry.saveStl("model.stl", { binary: true });
}
}