xxxxxxxxxx
68
let r = 100, g = 100, b =200
let z = -100;
let x = 0, y = 0 ;
let tempX, tempY, screenPositionGen;
let boxPositionX2D, boxPositionY2D;
function setup() {
createCanvas(400, 400,WEBGL);
avoidClipping();
addScreenPositionFunction();
}
function draw() {
background(255);
push();
fill(255);
fill(r,g,b);
translate(x,y,z);
ScreenPositionGen = screenPosition(0,0,0);
box(80,80,80);
pop();
z += 1;
boxPositionX2D = ScreenPositionGen.x;
boxPositionY2D = ScreenPositionGen.y ;
}
function avoidClipping() {
perspective(PI / 3.0, width / height, 1, 1000000);
}
function mouseClicked() {
// check if there is any difference in the values
//console.log(mouseX);
let d = dist(mouseX,mouseY,boxPositionX2D, boxPositionY2D);
console.log("X mouse : " + mouseX);
console.log("Y mouse : " + mouseY);
console.log("X snapshot : "+ boxPositionX2D);
console.log("Y snapshot : "+ boxPositionY2D);
console.log("distance : " + d);
if (d < 40) {
x= random(-200,200);//random(width);
y= random(-200,200);//random(height);
z = -1000;
r = random(0,255);
g = random(0,255);
b = random(0,255);
}
}