Skip to main content
Participating Frequently
February 1, 2025
Question

i want to bound circle within a box

  • February 1, 2025
  • 2 replies
  • 945 views

src=wiggle(2,200);
boundary = [135,135]; // size of boundinglayer/2
clamp(src, value - boundary, value + boundary)
how i do this in dynamic way , means if shape layer is rectangle and i want when ever i change height and weidth and bound upadated , balls are bounded inside the inner box because the box have stroke. bound also updated with stroke changes ,how can  ido that , can anyone give me idea?

2 replies

Inspiring
February 1, 2025

To respect the rectangle stroke width, you need to subtract it from the rectangle size,
As the size data is a 2D vector [x,y] and the stroke width is a single dimension float value you can put it twice in a 2D vector then subtract it from the size
var temp = << pickwip to insert it's code >> ;
var strokeWidth = [temp.temp] ;

then do the subtraction in parentheses before deviding by 2 (size - strokeWidth) /2

Participating Frequently
February 1, 2025

also i need to minus circle redius also ?

Inspiring
February 1, 2025

Sure, if you want to always keep the circle boundary inside the rectangle then you shoud subtract the circle size too.
(rectngleSize - circleSize - strokeWidth) / 2
but this assumes that the initial circle position is at the center of the rectangle, if not then you should calculate the clamp in a different way.

Inspiring
February 1, 2025

highlight this value [135,135] and use expression pickwip and choose the rectangle size then add /2

src=wiggle(2,200);
boundary = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Rectangle Path 1").size / 2; // size of boundinglayer/2
clamp(src, value - boundary, value + boundary)