xxxxxxxxxx
let handpose;
let video;
let predictions = [];
let angle = Math.PI;
let angleSpeed = 0.003;
let amplitude = 1200;
let skyfloater;
let skyopacity = 100;
let bg;
let sunpic;
let p1 =800;
let p2 = 800;
let sunX;
let sunY;
let skyglow;
let glowopacity = 0;
let glow;
let upcloud;
let upx = 0;
let lowcloud;
let lowx = 500;
let upspd = 3;
let lowspd = 8;
let skyt;
let hand;
function preload(){
skyfloater = loadImage('skyfinal.gif');
bg = loadImage('bgvip.jpg');
sunpic = loadImage('sun.png')
skyglow = loadImage ('skyradiation.gif')
glow = loadImage ('glow.png')
upcloud = loadImage ('123.png')
lowcloud = loadImage ('lowcloud.png')
skyt = createImg ('skytext.gif','text')
hand = loadImage ('goodbye.png')
}
function setup() {
createCanvas(1920,1080);
video = createCapture(VIDEO);
video.size(width, height);
handpose = ml5.handpose(video, modelReady);
handpose.on('predict', gotPredictions);
video.hide();
}
function modelReady() {
console.log('Model is ready!');
}
function gotPredictions(results) {
predictions = results;
}
function cloud(){
image(upcloud,upx,-150,2500,1200);
image(lowcloud,lowx,-150,2500,1500);
upx += upspd;
lowx += lowspd;
if (upx>width){
upx = -2500;
}
if (lowx>width){
lowx = -2500;
}
}
function mousePressed() {
if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
let fs = fullscreen();
fullscreen(!fs);
}
}
function draw() {
background(220);
frameRate(25);
translate(width, 0);
scale(-1, 1);
image(bg, 0, 0, width, height);
tint(255,120);
image(hand, 50, 50, 100, 100);
skyt.position(550,670);
skyt.size(900,500);
sunX = width /2 + cos(angle) * amplitude -500;
sunY = height/2 + sin(angle) * amplitude/2 - 400;
// Draw the arc
noFill();
noStroke();
// Draw the sun
fill(255, 0, 0);
image(sunpic,sunX, sunY, 1000, 1000);
// Update the angle for animation
angle += angleSpeed;
// Reverse the direction of motion when the circle reaches the end of the arc
if (angle > TWO_PI) {
angleSpeed *= -1;
} else if (angle < PI) {
angleSpeed *= -1;
}
for (let i = 0; i < predictions.length; i++) {
let hand = predictions[i].landmarks;
// Get the x and y coordinates of the index finger
let indexFingerX = hand[8][0] * (width / 640); // Adjust x-coordinate for new canvas size
let indexFingerY = hand[8][1] * (height / 480);
// skyfloater at the index finger's position
// ellipse(sunX+500, sunY+500, 50, 50);
//ellipse(indexFingerX+150, indexFingerY-100, 50, 50);
//print(`skyx, ${indexFingerX}`, `skyy, ${indexFingerY}`)//-950,79
//scale(-1, 1);
// Calculate distance between skyfloater and sun
let d = dist(indexFingerX+150, indexFingerY-100, sunX+500, sunY+500);
// Update skyfloater opacity based on collision with the sun
if (d < 200){
print ("bump!!!!")
skyopacity = max(100, skyopacity - 5);
glowopacity = min(180, glowopacity + 5); // opacity
} else {
skyopacity = min(105, skyopacity + 5);
glowopacity = max(0, glowopacity - 5)// opacity
}
tint(255, glowopacity);
image(skyglow, indexFingerX-190, indexFingerY-110, 400, 400);
image(glow, indexFingerX-190, indexFingerY-110, 400, 400);
tint(255, skyopacity);
image(skyfloater, indexFingerX-200, indexFingerY-100, 400, 400);
noTint();
}
//print (`sun x, ${sunX-1400}`,`sun y, ${sunY+538}`); //425,-459
tint(255, 255);
print(skyopacity)
cloud();
}