Stretching and tinting an object

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);
    }
  }
}
1 Like

I think tint works like stroke(); it has to be called before image(). And just like you call noStroke() when you don’t want a stroke, you have to call noTint()

2 Likes

In addition to what @tony says about removing tint() with noTint(), another option is that you can also push and pop tint states using pushStyle / popStyle.

This is helpful if you want to change tint in conjunction with other settings, or if you want to make several changes and then revert them.