xxxxxxxxxx
65
let y = 0;
let x = 0;
let y0 = 0;
let easing = 0.05;
let img;
function preload() {
img = loadImage("assets/image1.png");
}
function setup() {
createCanvas(360, 360, WEBGL);
document.ontouchmove = function (event) {
event.preventDefault();
};
}
function draw() {
image(img, -200, -200);
ambientLight(60, 60, 60);
pointLight(255, 255, 255, -100, -80, 100);
pointLight(255, 255, 255, -80, 40, 100);
push();
translate(0, 75, 80);
fill(192, 192, 210);
noStroke();
cylinder(80, 10);
translate(2, 10, 3);
cylinder(80, 10);
pop();
push();
if (mouseIsPressed) {
x = mouseX - x0;
y = mouseY - y0 - 50;
}
let targetX = 0;
let targetY = -50;
let dy = targetY - y;
let dx = targetX - x;
easing = 0.05;
x += dx * easing;
if (y < -50) easing = 0.2;
y += dy * easing;
translate(x, 25 + min(0, y), 50);
fill(140, 140, 200, 200);
noStroke();
rotateY(frameCount * 0.005);
randomSeed(0);
for (let i = 0; i < 10; i++) {
box(30 + random(10), 30 + random(10), 70 + random(10));
rotateX(random(50));
rotateY(random(50));
rotateZ(random(50));
}
pop();
}
function mousePressed() {
y0 = mouseY;
x0 = mouseX;
}
function mouseReleased() {
y = min(0, y);
}