Hi,
this is a bit different from Dan’s example wich uses random directions I believe.
A true-er pong motion if you will: ingoing angle is always the same as outgoing angle. Like those really old windows screensavers.
change the values in the first three lines.
apply expression to position-param:
box=[20,20,300,220]; // box you want to stay in [x1,y1,x2,y2]
motion=[312,123]; // motion-vector in pixels per sond [x,y]
startpos=[160,120]; // startposition
// calculations:
w=box[2]-box[0]; h=box[3]-box[1]; corner=[box[0],box[1]];
delta=motion*time; pos=startpos+delta-corner;
xx=pos[0]%(w*2); yy=pos[1]%(h*2);
corner+[xx