xxxxxxxxxx
72
let img;
let pointcloud;
function preload() {
// depthmaps via
// https://huggingface.co/sd-concepts-library/depthmap/
img = loadImage('bnw.jpeg');
blackhans=loadFont("BlackHanSans-Regular.ttf");
}
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
pointcloud = prepPoints(img,10);
console.log("num-of-points:", pointcloud.length);
}
function draw() {
background(0);
push();
fill(255);
noStroke();
// rotateX(frameCount*0.01);
translate(-506,-256);
let scl = 1;
fill(0,0,0,20);
// lights();
pointcloud.forEach((v,i)=> {
const x = v.x * scl;
const y = v.y * scl;
const t = frameCount*4 + i;
const z =cos(t*0.2)*20 - v.z;
const r = (frameCount*4+i)*1;
push();
translate(x,y,z);
// rotateX(r);
textFont(blackhans);
textSize(20);
stroke(255,0,0);
fill(240,0,91,100)
text("pumpkin",100 + z * 0.2,10);
pop();
});
pop();
if(mouseIsPressed) {
push();
translate(-img.width/2, -img.height/2);
image(img,0,0)
pop();
}
}
function prepPoints(theImg, theRes) {
let points = [];
for(let x=0;x<theImg.width;x+= theRes) {
for(let y=0;y<theImg.height;y+= theRes) {
let px = theImg.get(x,y);
let br = brightness(px);
if(br>20) {
points.push({x,y,z:br});
}
}
}
return points;
}
function keyPressed() {
if (key === 'f' || key === 'f') {
let fs = fullscreen();
fullscreen(!fs);
}
}