Hi to all,
I'm trying to save layers position's to an array and, later, recover them on depending of layer index and a random number pick up on a Null layer.
The expresion is this:
And what exactly is your question (aside from the code generally making no sense)?
Thank you Mylenium. The questiosn is that I wonder why is not working, I'm getting overlapping layers when I suppose to get distribuyed layers. The first 8 layers works poperly but the rest are repeating positions
And what's the issue?
I'm getting this
when I want this
I think those lines are creating the overlapping squares:
Thank you Martin,
The reason why I though I have to use those lines is that I wanted to no repeat positions of the squares and there are 24 layers, so the layer index plus the result of the random give me one unique number for that layer, and if it pass 24 it could use an index whic it's in the range (0-24). In addition to this I use the $.evalFile() to only write one expression.
"If you just aiming for shuffling colors, just randomize the color of each square." It's another approach I was thinking of, but I wanted to try to learn how to make it works this way
"so the layer index plus the result of the random give me one unique number" - yes, that is true and you'll get the same result just using the random in a range of 0,25. It's easier, less lines, more logic.
However, none of those approches will prevent you from getting repeated postions, because 7.4566 and 7.1293 are two unique random numbers, but math.floor(random(...)) will make both of them to 7.
Using Math.round() might be a better approach, but still not a bulletproof solution (7.64 and 8.001 will be both 8).
This is a good example why expressions really should have global variables...
My recommendation is to just shift the colors, not the squares, because you cannot easily prevent having double integers, as I stated above. When only shifting colors, however, you can prevent a visual "black hole" - instead you will only get same colors two times which is hard to notice anyways.
One last glimps of hope is, that expressions might be evaluated layer by layer and not parallel for all layers. I'm not sure about this, but if AE is evaluating layerwise, you can check if another layer is already at the postion you want to set the current layer to.
In this scenario, you need to know if AE evaluates from top to buttom of the layer stack, or buttom to top.
Taking the second case, a layer could questioning: "I picked a random number and this turns out to a given position, is a layer below me already at this position? If yes, I pick another random number and ask again - if not, I take this position".
Thank you Martin,
As you said, there were "black holes" in those approaches. I've tried the shuffleArray from Slack, and precomposing and duplicating those I've fixed it, so it works for me, but as you also said, it wold be nice to have global variables.
Thank you for your help .