ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

How get a random position with fixed numbers

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Levris Levr
How get a random position with fixed numbers
on Oct 12, 2017 at 10:55:37 pm

I heave a fixed positions for X - simple [1, 4, 6, 9, 45, etc] and fixed posotions for Y [3, 8, 56, 32, etc]
What expressions i need to use to set my object in random X position of [1, 4, 6, 9, 45, etc] and Y of [3, 8, 56, 32, etc] in every frame ?


Return to posts index

Andrei Popa
Re: How get a random position with fixed numbers
on Oct 13, 2017 at 7:35:54 am

I don't know how you save your variables. I will asume that you declare them inside your expression. This first expression if for using same position of x and y(third x matches third y)
xArray = [100,300,500,700];
yArray = [200,400,600,800];
randomPosition = Math.round(random()*(xArray.length-1));
x = xArray[randomPosition];
y = yArray[randomPosition];
[x,y]


This code is for using random x and random y.

xArray = [100,300,500,700];
yArray = [200,400,600,800];
xrandomPosition = Math.round(random()*(xArray.length-1));
yrandomPosition = Math.round(random()*(xArray.length-1));
Math.floor(random()*xArray.length);
x = xArray[xrandomPosition];
y = yArray[yrandomPosition];
[x,y]


Feel free to ask if you need any further explanation.

Andrei


Return to posts index

Levris Levr
Re: How get a random position with fixed numbers
on Oct 13, 2017 at 11:54:29 am

Thanks !!!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]