Skip to main content
Participant
January 21, 2024
Question

How to make position only move inside the screen boundary after adding time expression

  • January 21, 2024
  • 2 replies
  • 235 views

Hello,

I want to move a watermark around the screen like the old dvd players used to do. Rather than manually making a mask path, I intended on using expression to achieve this effect. I currently have modulated the watermark to move around by:

 

speed=50;

position + [time,time]*speed

 

This achieves the movement, but the position moves continually off screen and does not stay within. How can i create boundaries to stop position from moving off screen?

 

Best,

Rat

This topic has been closed for replies.

2 replies

Legend
January 21, 2024

Position Expression: 

 

seedRandom(index, true);

w = sourceRectAtTime().width * scale[0] / 100;
h = sourceRectAtTime().height * scale[1] / 100;

offset = 5; // offset or speed

// random start position
x = w / 2 + Math.floor(Math.random() * thisComp.width - w) - offset;
y = h / 2 + Math.floor(Math.random() * thisComp.height - h) - offset;
dx = 1;
dy = 1;

path = [];
for (var i = 0; i <= timeToFrames(time); i++) {
  x += dx * offset;
  y += dy * offset;
  x = clamp(x, w / 2, thisComp.width - w / 2);
  y = clamp(y, h / 2, thisComp.height - h / 2);
	
  if (x >= thisComp.width - w / 2 || x <= w / 2) {
    dx *= -1
  }
  if (y >= thisComp.height - h / 2 || y <= h / 2) {
    dy *= -1
  }
  path.push([x, y])
}
path[timeToFrames(time)]

 

 

Mylenium
Legend
January 21, 2024

You need to limit the ranges by using linear() expressions comparing position to comp width and such and of course you'd need further code to do the direction changes.

 

Mylenium