Hello Processors, thank you for your time. I have a video object that bounces around and I program it so that when you mousePressed on either of its iterations it stretches but the mouse arrow moves awkwardly to the 0,0 coordinates of the video object being pressed. Also, Inside the same if statement where I wrote the part that recognizes that the arrow is inside the video I place a tint function because I want to tint only the single object I am pressing but instead it tints all object copies.
import processing.video.*;
Movie myMovie;
int numVideos = 10;
float spring = 0.05;
float gravity = 0.03;
float friction = -0.9;
Video[] videos = new Video[numVideos];
void setup() {
size (640, 640);
myMovie = new Movie(this, "fogata.mp4");
myMovie.loop();
for (int i = 0; i < numVideos; i++) {
videos[i] = new Video(random(4096/60), random(2160/60),random(100, 180), i, videos);
}
}
void draw() {
background(255);
for (Video video : videos) {
video.collide();
video.move();
video.display();
}
}
void movieEvent(Movie m) {
m.read();
}
class Video {
float x, y, area;
float posX, posY;
float sizeH;
float vx = 0;
float vy = 0;
int id;
Video[] others;
Video(float w, float h, float din, int idin, Video[] oin) {
x = w;
y = h;
area = din;
id = idin;
others = oin;
}
void collide() {
for (int i = id + 1; i < numVideos; i++) {
float dx = others[i].x - x;
float dy = others[i].y - y;
float distance = sqrt(dx*dx + dy*dy);
float minDist = others[i].area/2 + area/2;
if (distance < minDist) {
float angle = atan2(dy, dx);
float targetX = x + cos(angle) * minDist;
float targetY = y + sin(angle) * minDist;
float ax = (targetX - others[i].x) * spring;
float ay = (targetY - others[i].y) * spring;
vx -= ax;
vy -= ay;
others[i].vx += ax;
others[i].vy += ay;
}
}
}
void move() {
vy += gravity;
x += vx;
y += vy;
if (x + area/2 > width) {
x = width - area/2;
vx *= friction;
} else if (x - area/2 < 0) {
x = area/2;
vx *= friction;
}
if (y + area/2 > height) {
y = height - area/2;
vy *= friction;
} else if (y - area/2 < 0) {
y = area/2;
vy *= friction;
}
}
//stretch
void display() {
if (mousePressed== true && mouseX>x && mouseX<x+area && mouseY>y && mouseY<y+area) {
image(myMovie, mouseX, mouseY, mouseX, mouseY);
tint(0,255,0);
} else {
image(myMovie, x, y, area, area);
}
}
}