# Stretching and tinting an object

**URL:** <https://discourse.processing.org/t/stretching-and-tinting-an-object/3050>\
**Category:** Coding Questions\
**Created:** [August 28, 2018, 4:28am UTC](https://discourse.processing.org/t/stretching-and-tinting-an-object/3050 "2018-08-28T04:28:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tefa](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tefa/32/1181_2.png) [@tefa](https://discourse.processing.org/u/tefa)\
**Post date:** [August 28, 2018, 4:28am UTC](https://discourse.processing.org/t/stretching-and-tinting-an-object/3050/1 "2018-08-28T04:28:14Z")

</div>

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.

```auto
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);
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![tony](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tony/32/949_2.png) [@tony](https://discourse.processing.org/u/tony)\
**Post date:** [August 28, 2018, 6:16pm UTC](https://discourse.processing.org/t/stretching-and-tinting-an-object/3050/2 "2018-08-28T18:16:31Z")

</div>

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()](https://processing.org/reference/noTint_.html)

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 4, 2018, 5:55pm UTC](https://discourse.processing.org/t/stretching-and-tinting-an-object/3050/3 "2018-09-04T17:55:15Z")

</div>

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.

- [https://processing.org/reference/tint\_.html](https://processing.org/reference/tint_.html)
- [https://processing.org/reference/pushStyle\_.html](https://processing.org/reference/pushStyle_.html)
- [https://processing.org/reference/popStyle\_.html](https://processing.org/reference/popStyle_.html)
