Skip to main content
Participating Frequently
December 19, 2024
Question

Expression Position / Anordnung von vielen Objekten zu einer Form

  • December 19, 2024
  • 1 reply
  • 393 views

Hallo zusammen, ich bräuchte Hilfe bei der Erstellung einer Expression. Ich habe 35 Objekte, die am Anfang zufällig verteilt sind und am Ende der Animation eine Form ergeben sollen.
Da ich kein Coder bin, kam ich mit den Standard Tutorials zu Random() oder Schieberegler Position verschieben, ... nicht weit. Hat mir jemand von Euch ein paar Tipps vielleicht auch ein Tutorial?

Danke!!

LG

This topic has been closed for replies.

1 reply

Legend
December 19, 2024

Try this:

 

1 / Place your layers correctly

 

2/ Add this expression to the position property of the layers to animate them randomly.

seedRandom(index, true);

w = sourceRectAtTime().width;
h = sourceRectAtTime().height;
cw = thisComp.width;
ch = thisComp.height;

sx = Math.random() * (cw - w) + w / 2;
sy = Math.random() * (ch - h) + h / 2;
startPos = [sx, sy];

endPos = value;

randomSpeed = Math.random() * 2 + 1;
t = linear(time, 0, randomSpeed, 0, 1);

[
    linear(t, 0, 1, startPos[0], endPos[0]),
    linear(t, 0, 1, startPos[1], endPos[1])
]

 

 

Participating Frequently
December 19, 2024

Fantastic. Thank you very much. Some objects “run” beyond the comp size. How can I prevent this or specify the max. size? I tried to change the value at (cw - w) + w / 2, but nothing happened. Unfortunately I am not a coder and understand almost nothing of what is written in the code 😕😕

Legend
December 19, 2024

Try this, it should take the layers' scale and anchor point into account:

seedRandom(index, true);

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

cw = thisComp.width;
ch = thisComp.height;

halfW = w / 2;
halfH = h / 2;

sx = Math.random() * (cw - w) + halfW;
sy = Math.random() * (ch - h) + halfH;

scaledAnchor = [
    anchorPoint[0] * scaleFactor[0],
    anchorPoint[1] * scaleFactor[1]
];

startPos = [sx + scaledAnchor[0], sy + scaledAnchor[1]];
endPos = value;

randomSpeed = Math.random() * 2 + 1;
t = Math.min(time / randomSpeed, 1);

linear(t, 0, 1, startPos, endPos);